Forums Register Login

org.hibernate.AnnotationException: No identifier specified for entity

+Pie Number of slices to send: Send
I have this table:


The QuestionTest class only has the mapping:
@ManyToOne
private Question question;
@ManyToOne
private Test test;

I know that the problem can be solved creating an id field, but I don't want to do it. I want the primary key to be the composite key.
Is it possible? How can I do this?

+Pie Number of slices to send: Send
If you're using Hibernate you can put @Id on both of attributes
this will make it a composite.However, I don't think that you should map a relation table as an entity.
+Pie Number of slices to send: Send
You can do this in the following way.


public class NameId implements Serializable
{
protected String name;
protected int type;
protected String neName;

//Getters and Setters follows
}


@Entity
@Table(name = "NAME_")
@IdClass(NameId.class)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Name Serializable
{
@Id
protected String name;
@Id
protected int type;

protected String MOType;
@Id
protected String neName;
public Name()
{

}
//Getters and Setters follows
}


+Pie Number of slices to send: Send
 

Muhammad Ramahy wrote:If you're using Hibernate you can put @Id on both of attributes


If I put @Id in both a get this.
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: questionapp.model.QuestionTest.test in questionapp.model.Test.questionsTests

Muhammad Ramahy wrote:However, I don't think that you should map a relation table as an entity.


What do you do then?
+Pie Number of slices to send: Send
 

Repala Madhu wrote:You can do this in the following way.


Thanks for mention @IdClass
I followed this tutorial http://www.ibm.com/developerworks/java/library/os-hibernatejpa/index.html
But it's not working for me. I don't know what I'm missing.

When I try to save


I get this error java.lang.ClassCastException: questionapp.model.QuestionTestPK cannot be cast to java.lang.Integer

+Pie Number of slices to send: Send
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 20998 times.
Similar Threads
JPA data retrieval query
HQL query required with left outer join
Storing XML in the Database
Testing @ManyToOne Relationships
hibernate:many-to-many the association table is not getting populated
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:08:51.