Question

I have implemented one-to-many relationships for entity. So those are mapped with another entity to pass the value.

@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="part_id")
    public Part getPart() {
        return part;

part_id doesn't create getters and setters with @column.Its only setting up with relationship.

But in other scenarios i have check these fields in query.I'm trying to use Criteria to find the values

Its giving me exception org.hibernate.QueryException: could not resolve property: part_id because didn't generate getter with @Column property.Could you please advise how to use these fields in query ?

if add getters and setters, its giving org.hibernate.MappingException: Repeated column in mapping for entity:.

Thanks,

Was it helpful?

Solution

Bi-Direction Association(link) should be as below.

@Entity
public class Troop {
    @OneToMany(mappedBy="troop")
    public Set<Soldier> getSoldiers() {
    ...
}

@Entity
public class Soldier {
    @ManyToOne
    @JoinColumn(name="troop_fk")
    public Troop getTroop() {
    ...
}       

Kindly check the configuration. If possible use hibernate tools to generate the entity.

OTHER TIPS

Instead of using names of database columns, names of persistent properties should be used. In this case name of the persistent property is part. If goal is to fetch all such entities that are related to part with given id, then following is way to go (name of the id property in Part is assumed to be id):

crit.add(Restrictions.eq("part.id", partId));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top