[jboss-user] [EJB 3.0] - Question @Inheritance

pKraemer do-not-reply at jboss.com
Wed Apr 11 12:51:32 EDT 2007


Well it's me again with a question for using @Inheritance

Well I got one super Entity:


  | @Entity
  | @Table(name="users")
  | @SequenceGenerator(name = "user_sequence", sequenceName = "user_id_seq")
  | @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
  | public class User implements Serializable {
  | 
  | 	private static final long serialVersionUID = 1487970457796785528L;
  | 	@Id
  | 	@Column(name="u_id",nullable=false)
  | 	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_sequence")
  | 	private Long id;
  | ....
  | }
  | 

and a child class


  | @Entity
  | @Table(name="registered_user")
  | public class RegisteredUser extends User implements Serializable{
  | 
  | 	private static final long serialVersionUID = 2027308984532828735L;
  |  ....
  | }
  | 

with no specific id.

Both entities are represented by an own table. The Primary Key from the parent table is also used as primary key in child table (mapped with foreign key)

When I try to persist a child object I got an Error:

anonymous wrote : 
  | 18:19:46,968 ERROR [JDBCExceptionReporter] ERROR: insert or update on table "registered_user" violates foreign key constraint "fk22ff4768223777df"
  |   Detail: Key (u_id)=(1600) is not present in table "users".
  | 18:19:46,968 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
  | 

How can I tell the manager to persist the attributes in my parent table? Perhaps with cascade strategy? And where should I put it?

Thx a lot

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4036448#4036448

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4036448



More information about the jboss-user mailing list