-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem with inheritance and primary key in the sub-class
PostPosted: Mon Oct 23, 2006 1:17 pm 
Newbie

Joined: Mon Oct 23, 2006 12:51 pm
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

I have create an hierarchy betwen 2 class A and B. It work,
the superclass have a primary key. I want to add another attribute in the primary key to the sub class B.

A with the primary key id
B with the primary key id ( from A) and c definited in the sub-class




Hibernate version: 3.2.0.GA


...
session = sessionFactory.openSession() and
Transaction tx = session.beginTransaction();
B b = new B();
b.setC(1);
b.setD(2);
AId aid =new AId();
aid.setA(1);
aid.setB(2);
b.setId(aid);

session.save(b);
tx.commit();
session.flush();




@Entity(name="A")
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)

public class A implements Serializable{
@Id
private int id;
public class A implements Serializable{
@Id
private AId id;

/** Creates a new instance of A */
public A() {
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}
}


@Entity(name="b")
public class B extends A {

@Id
@Column(name="c")
private int c;
private int d;


/** Creates a new instance of B */
public B() {
}

public int getC() {
return c;
}

public void setC(int c) {
this.c = c;
}

public int getD() {
return d;
}

public void setD(int d) {
this.d = d;
}
}




I tried in this way, but it doesn't work.



Full stack trace of any exception that occurs:

org.hibernate.AnnotationException: Unable to define/override @Id(s) on a subclass: it.gesan.prova.B
at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1686)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1171)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:706)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:452)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:268)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1210)
at it.gesan.gvf.storage.util.HibernateUtil.<clinit>(HibernateUtil.java:91)
java.lang.ExceptionInInitializerError
at it.gesan.gvf.storage.util.HibernateUtil.<clinit>(HibernateUtil.java:96)
Caused by: org.hibernate.AnnotationException: Unable to define/override @Id(s) on a subclass: it.gesan.prova.B
at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1686)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1171)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:706)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:452)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:268)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1210)
at it.gesan.gvf.storage.util.HibernateUtil.<clinit>(HibernateUtil.java:91)




database i am using: mysql 5


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.