Reputation: 16158
I am generating hibernate pojo classes with annotations from existing tables using Ant Script. I am stuck with a problem. Problem is that I am having two classes Person and Address. There is OneToMany mapping between these two classes.
Generated classes contains :
//Person.java
@OneToMany(fetch=FetchType.LAZY)
public Set<Address> getAddresses()
{
return addresses;
}
public void setAddresses(Set<Address> addresses)
{
this.addresses=addresses;
}
//Address.java
@OneToMany(fetch=FetchType.LAZY)
public Person getPerson()
{
return person;
}
public void setPerson(Person person)
{
this.person=person;
}
I am having a situation where I don't want to generate the set of addresses. Is there any way to generate the POJOs without set. i.e. to avoid the reverse mapping. Please help. Thanks in advance.
Upvotes: 2
Views: 1245
Reputation: 10131
I'm making an assumption here, but I think you use the Hibernate Tools for Ant to generate entity classes. These tools (as far as I remember) generates classes based on Hibernate mapping XMLs (hbm.xml).
I am generating hibernate pojo classes with annotations from existing tables using Ant Script. I am stuck with a problem. Problem is that I am having two classes Person and Address. There is OneToMany mapping between these two classes.
You've said that the Person and Address class, which are, or at least should be, mappings of tables in your database, are in a 1:N relation. (One person can have multiple addresses, while an address can belong only to a single person.) As such, you should have a Person.hbm.xml and Address.hbm.xml file somewhere around. This means, that if your mapping files are correct then a Set<Address> field (with a getter and setter method) will be generated by the Hibernate Tools, because that's how it works.
I'm not an active user of this tool, but as I see you have the following options.
(I really don't know much about Hibernate Tools, so maybe it's possible to entirely omit the methods in question via some configuration, but it would be really inappropriate to do so nonetheless.)
Upvotes: 1