• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

org.hibernate.AnnotationException: No identifier specified for entity

 
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Greenhorn
Posts: 11
jQuery Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
}


 
Leandro Coutinho
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Leandro Coutinho
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Muhammad Ramahy
Greenhorn
Posts: 11
jQuery Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
take a look at this example: http://www.vaannila.com/hibernate/hibernate-example/hibernate-mapping-many-to-one-using-annotations-1.html
 
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic