-->
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: Composite id with annotations
PostPosted: Wed Mar 26, 2008 8:41 am 
Newbie

Joined: Wed Mar 26, 2008 7:42 am
Posts: 1
Hello,
I am using Hibernate 3.2.4 sp1 and Hibernate Annotations 3.3.0.
I have a single database table that has 2 id's that make up its composite
id. Hence, I would like to create an entity class that maps this table.
The pattern I used was the pattern in the "Java Persistence with Hibernate"
text starting on page 330. First I created an id class. Iam confident
that this id class is correct because this mapping works when I use a
regular old mapping file (*.hbm.xml). The problem comes in when I try
to use the following entity class:


Mapping class

@Entity
@Table(name="database..my_composite_id_table")
@IdClass(MyIds.class)
public class TestComposite
{
@Id
@Column(name="actual_column1")
private Long id1;


@Id
@Column(name="actual_column2")
private Long id2;

//Plus getters and setters
}


Id class (no annotations at all in this class)

public class MyIds
{
private Long id1;
private Long id2;

//Plus getters and setters
//Plus CORRECT implementations of hashcode and equals

}

Iam simply trying to use the patterns in the textbook. Specifically
on page 332.

Now, querying the TestComposite class with

...
Query q = session.createQuery(" from TestComposite t where t.id1 = 123")
...

I get the error:

WARN JDBCExceptionReporter:... "Invalid column name 'id1' ...



Any Ideas?
Thanks


Top
 Profile  
 
 Post subject: Re:composite key
PostPosted: Fri Mar 28, 2008 10:17 am 
Newbie

Joined: Fri Mar 28, 2008 10:02 am
Posts: 1
try using column annotation for each property in compositeKey class as property name and column names are different


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.