Joined: Tue Dec 14, 2004 12:54 pm Posts: 4 Location: Bangalore, India
|
Hello
I am having a Base Class called Person having a primary key.
Now there is a sub class called Customer which extends Person and the Customer class having many-to-one & one-to-many relationship.
Mapping Class
<class name="HibernateDemo.Project.iJET.Customer" table="CUSTOMERX">
<id name="id" type="int" unsaved-value="0" >
<column name="id" sql-type="number(38)" not-null="true"/>
<generator class="increment"/> </id>
<property name="company_name" column="COMPANY_NAME" type="string" />
<many-to-one name="address" class="HibernateDemo.Project.iJET.Address" column="id"/>
<set name="telephone" cascade="all" inverse="true" lazy="true">
<key column="id"/>
<one-to-many class="HibernateDemo.Project.iJET.Telephone"/>
</set>
<one-to-one name="person" class="HibernateDemo.Project.iJET.Person" constrained="true" cascade="all" />
</class>
</hibernate-mapping>
Bean Class
class Customer extends Person
{
private String company_name;
private Address address;
private Set telephone;
public String getCompany_name()
{return company_name; }
.........
public Set getTelephone()
{return telephone;}
public void setTelephone(Set telephone)
{this.telephone=telephone;}
Main Class
Configuration config=new Configuration()
.addClass(Customer.class)
.addClass(Person.class)
.addClass(Telephone.class)
SessionFactory sf = config.buildSessionFactory();
Session sess = sf.openSession();
Transaction tx = null;
try {
tx = sess.beginTransaction();
Customer customer = new Customer();
customer.setName("Raj");
customer.setAge(24);
customer.setCompany_name("TurningPoint Software");
........
This is the Error
net.sf.hibernate.MappingException: Repeated column in mapping for class Hibernat
eDemo.Project.iJET.Customer should be mapped with insert="false" update="false": id at net.sf.hibernate.persister.AbstractEntityPersister.checkColumnDuplica
tion(AbstractEntityPersister.java:978)
at net.sf.hibernate.persister.NormalizedEntityPersister.<init>(Normalize
dEntityPersister.java:878)
Kindly give me the answer. Thanks for advance.
|
|