org.hibernate.AnnotationException: @OneToOne or @ManyToOne on xxx references an unknown entity: xxx

January 22, 2009

Context :

During the process of converting the old hibernate xml heavy structure to the new annotation based structure, the following error was encountered after annotating one of the entity files…

org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.project.entityone.model.EntityOne.addedBy references an unknown entity: com.project.entitytwo.model.EntityTwo

… seemed like new annnotated entity was not being recognised by hibernate !

Solution :

1) Ensure that the entity has been appropriately referenced in hibernate.cfg.xml

ie

<hibernate-configuration>
    <session-factory>
        ...
        <mapping class="com.project.entitytwo.model.EntityTwo"/>
        ...
    </session-factory>
</hibernate-configuration>

2) Ensure that @Entity has been specified at the class-level ( at the top of the class )

ie.

@Entity
@Table( name="ENTITY_TWO" )
public class EntityTwo extends AbstractPersistanceClass
{
    ...

Wa Allahu ‘Alam

Entry Filed under: Hibernate, Java, Netbeans. Tags: , , , .

2 Comments Add your own

  • 1. Dieterich  |  July 22, 2009 at 4:36 am

    Additionally, you have to make sure that all your annotations are the same. There is an @Entity annotation in both the hibernate api and the Java persistence API. All annotations must be either one or the other, which you can ensure by looking at your imports.

    Reply
    • 2. Geapetto  |  September 8, 2009 at 8:06 pm

      Thanks Dieterich

      Reply

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Recent Posts

Recent Comments

Categories

Top Posts

Links

Blog Stats

Meta