-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problems with @SequenceGenerator and @IdClass
PostPosted: Sun Feb 15, 2009 10:29 am 
Newbie

Joined: Fri Feb 13, 2009 5:43 pm
Posts: 4
I am having problems using Oracle sequence generators in a composite primary key.

I am using Hibernate 3.2.3 , Oracle 10g

I have a table, CHILDS, with primary key ( parent_Id, child_Id ) .

I started using @EmbeddedId - which worked well.

Until I tried to use an Oracle Sequence Generator to generate the child_id value during an insert. Could not get it working. ( Oracle sequence generator name = "SQ_CHILD_ID" )

Then discovered that couldn't use @EmbeddedId with @GeneratedValue / @SequenceGenerator
[url]http://forums.hibernate.org/viewtopic.php?p=2393944&sid=57b20ef2c7de6f6bcba632130987bc22
[/url]
So then used an @IdClass instead. Again , same ORA error ( Cannot insert NULL into CHILDS.CHILD_ID ).

Any suggestions would be very helpful.

Here is the code snippet using IdClass



@Entity
@Table( name="CHILDS" )
@IdClass( ChildsId.class )
public class Child implements Serializable {

Integer parentId ;
Integer childId ;

[color=red] @Id
@Column(name = "CHILD_ID", nullable = false, precision = 8, scale = 0)
@SequenceGenerator( name="SQ_CHILD_ID", sequenceName="SQ_CHILD_ID" )
@GeneratedValue( strategy=GenerationType.SEQUENCE, generator="SQ_CHILD_ID")
[/color] public Integer getChildId() {
return childId ;
}

public void setChildId( Integer id ) {
childId = id ;
}

@Id
@Column(name = "PARENT_ID", nullable = false, precision = 8, scale = 0)
public Integer getParentId() {
return parentId;
}
public void setParentId( Integer id ) {
parentId = id ;
}
}

public class ChildsId implements Serializable{
Integer parentId ;
Integer childId ;

[color=red] @Column(name = "CHILD_ID", nullable = false, precision = 8, scale = 0)
@SequenceGenerator( name="SQ_CHILD_ID", sequenceName="SQ_CHILD_ID" )
@GeneratedValue( strategy=GenerationType.SEQUENCE, generator="SQ_CHILD_ID") [/color]
public Integer getChildId() {
return childId ;
}

public void setChildId( Integer id ) {
childId = id ;
}

@Column(name = "PARENT_ID", nullable = false, precision = 8, scale = 0)
public Integer getParentId() {
return parentId;
}
public void setParentId( Integer id ) {
parentId = id ;
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 21, 2009 3:05 am 
Newbie

Joined: Sun Jul 06, 2008 7:05 pm
Posts: 6
bump


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

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.