3 Replies Latest reply on Sep 11, 2012 7:33 AM by Wolf-Dieter Fink

    JPA error on @JoinColumn or @ManyToOne @OneToMany

    Ryan Li Newbie

      I made a mistake in placing a foreign key.

      but I don't really get what's wrong. Can I place @JoinColumn and @ManyToOne together?

      I have followed what shown on the book

      Could somebody help me out? giving me some hint on fixing it. thanks!

      the error stall the deployment and do a rollback.

      2 entities and part of the stack trace posted.

       

       

       

      package com.h2o;

       

      import javax.persistence.*;

       

      @Entity

      public class ImageBase {

       

         

          @Id @GeneratedValue(strategy=GenerationType.SEQUENCE)

          private Long id;

          @Column(unique=true)

          private String imgFile;

          @Column(nullable=true)

          private String imgOriginalFile;

          @ManyToOne

          @JoinColumn

          private h2oUser user;

          //setters and getters

      }

       

       

       

      package com.h2o;

       

      import javax.persistence.*;

      import java.util.*;

       

      @Entity

      @IdClass(h2oUserId.class)

      @NamedQuery(name="findAllUsers", query="SELECT h FROM h2oUser h")

      public class h2oUser {

       

          @Id @GeneratedValue(strategy=GenerationType.SEQUENCE) @Column(name="H2O_ID")

          private Long id;

          @Id

          @Column ( nullable = false)

          private String email;

          @Column ( nullable = false)

          private String nickName;

          @Column ( nullable = false)

          private String password;

          private String basePath;

          private String avatorPath;

          private boolean activated;

          @Temporal(TemporalType.DATE)

          private Date createDate;

          @Transient

          private static final String LARGE = "original";

          @Transient

          private static final String SMALL = "thumbernail";

          @OneToMany(mappedBy="h2oUser")

          private Collection<ImageBase> images;

       

          //getters and setters

      }

       

       

      Caused by: org.hibernate.MappingException: Could not determine type for: com.h2o.h2oUser, at table: ImageBase, for columns: [org.hibernate.mapping.Column(user)]

          at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:304)

          at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:288)

          at org.hibernate.mapping.Property.isValid(Property.java:216)

          at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:467)

          at org.hibernate.mapping.RootClass.validate(RootClass.java:268)

          at org.hibernate.cfg.Configuration.validate(Configuration.java:1287)

          at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1729)

          at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84)

          at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)

          ... 9 more