This discussion is archived
12 Replies Latest reply: Feb 17, 2012 4:27 AM by gimbal2 RSS

Uses a non-entity as target entity

917543 Newbie
Currently Being Moderated
Hi everyone,

I need your help because I am working on a project j2ee6

I am using jpa (eclipseLink)

when I created entities without relation, all worked perfectly

but now that I am trying to set up relation @oneTomany @ManyToOne

I got this error all the time

Exception Description: [class com.Domain.User] uses
[ERROR] a non-entity [class com.Domain.Groups] as target entity in the
[ERROR] relationship attribute [field groupe].


here is my user entity :_

@Entity
@NamedQueries({
     @NamedQuery(name = "findAllUsers", query="select u from User u"),
     @NamedQuery(name = "findWithLogParam", query="select u from User u where u.Email = :fmail and u.Password = FUNC('sha1', :fpass)")
})
public class User implements Serializable{
     
     /**
     *
     */
     private static final long serialVersionUID = 3175161374832714727L;
     
     @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
     private Long UserId;
     @Column(nullable = false)
     private String Title = "Mr";
     @Column(nullable = false)
     private String Login;
     @Column(nullable = false)
     private String Password;
     @Column(nullable = false)
     private String Firstname;
     @Column(nullable = false)
     private String Lastname;
     @Column(nullable = false)
     private String Email;
     private String Telephone;
     private String Mobile;
     @Temporal(TemporalType.DATE)
     private Date Date_of_birth;
     private String Postcode;
     private String Address;
     private String City;
     private String County;
     private String Region;
     private String Country;
     private String AccountEnabled="On";
     
     @ManyToOne(optional=false)
@JoinColumn(name="GROUPID", referencedColumnName="GROUPID")
     private Groups groupe;
     private String Token;

Here is the entity Groups*

@Entity
public class Groups implements Serializable{
     

     private static final long serialVersionUID = 7092895671981671161L;
     
     @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
     private Long GroupId;
     @Column(nullable = false)
     private String GroupName;      
     
     @OneToMany(mappedBy="groupe", targetEntity=User.class, fetch=FetchType.EAGER)
     private List<User> UserList = new ArrayList<User>();

Here is my persistence.xml*

<?xml version="1.0" encoding="windows-1252" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
               version="2.0">
     <persistence-unit name="testPU" transaction-type="JTA">
          <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>     
          <jta-data-source>jdbc/UnmodDB</jta-data-source>     
          <class>com.unmod.Domain.User</class>
          <class>com.unmod.Domain.Groups</class>
........ other classes ......
          <exclude-unlisted-classes>false</exclude-unlisted-classes>
          <properties>
               <property name="eclipselink.target-database" value="MySQL"/>
               <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
               <property name="eclipselink.ddl-generation.output-mode" value="database" />
          <property name="eclipselink.create-ddl-jdbc-file-name" value="create.sql"/>
          </properties>
     </persistence-unit>
</persistence>


It works (compliation works) when I add @Basic however only the user table is created

Thanks
  • 1. Re: Uses a non-entity as target entity
    gimbal2 Guru
    Currently Being Moderated
    Strange. A few observations:

    - this seems to be deployed in an application server (because the transaction-type is JTA). You do not have to manually define the entity classes in your persistence.xml file, the container will do this for you automatically.
    - JPA works on conventions. You don't need to define attributes like 'referencedColumnName' and 'targetEntity'. You should keep the configuration as minimal as possible.

    Anyway, based on the information your provide, which is the following:

    - you get the non-entity error
    - the groups table is not auto-generated

    I can conclude only one thing basically: the Groups class is not deployed or in the wrong package. I think the latter, because if you look at the error message:
    a non-entity [class com.Domain.Groups]
    and the persistence.xml declaration:
    <class>com.unmod.Domain.Groups</class>
    you can clearly see the packages don't match up. Probably removing the <class> elements from the persistence.xml will already fix your problems.
  • 2. Re: Uses a non-entity as target entity
    917543 Newbie
    Currently Being Moderated
    Hi Gimbal2,

    Thanks for your replie

    about the package in the error message, I cleaned the error message before posting it on the forum so as to avoid confusion.
    but it was the opposite :

    here is the error
    Exception Description: [class com.unmod.Domain.User] uses
    [ERROR] a non-entity [class com.unmod.Domain.Groups] as target entity in the
    [ERROR] relationship attribute [field groupe].

    I cleaned the persistence.xml by deleting the classes and then in a second , I removed the useless attributes you mentioned.

    I have the same error.
  • 3. Re: Uses a non-entity as target entity
    gimbal2 Guru
    Currently Being Moderated
    Yes well, keep digging. There is nothing strange about your classes and the configuration looks fine. Try cleaning the deployed application, cleaning your IDE project and completely redeploying everything.
  • 4. Re: Uses a non-entity as target entity
    917672 Newbie
    Currently Being Moderated
    take this line out:

    @JoinColumn(name="GROUPID", referencedColumnName="GROUPID")

    you don't need both @ManyToOne mapping and the @JoinColumn

    Amy
  • 5. Re: Uses a non-entity as target entity
    gimbal2 Guru
    Currently Being Moderated
    914669 wrote:
    take this line out:

    @JoinColumn(name="GROUPID", referencedColumnName="GROUPID")

    you don't need both @ManyToOne mapping and the @JoinColumn

    Amy
    Not accurate. You may not need it, but when the column name in the database is different from the property name in the entity (for example because the database uses a ridiculous naming scheme), you do need JoinColumn to specify the proper column name. In any other case, Having a JoinColumn annotation does not hurt so I don't see why you offer it as advice.
  • 6. Re: Uses a non-entity as target entity
    917543 Newbie
    Currently Being Moderated
    nothing changed the result is the same

    even after cleaning the project / maven
    reinstalled glassfish
    changed the database

    and used

    @OneToMany
         @JoinTable(name = "Config",
         joinColumns = {
         @JoinColumn(name="UserId", unique = true)
         },
         inverseJoinColumns = {
         @JoinColumn(name="ConfId")
         }
         )

    I obtained the same error for any relation I set up.

    I don't understand nobody got this kind of error .
  • 7. Re: Uses a non-entity as target entity
    gimbal2 Guru
    Currently Being Moderated
    914540 wrote:
    I don't understand nobody got this kind of error .
    Well I don't use EclipseLink, I use Hibernate. But I believe EclipseLink is bundled with Glassfish and Sun/Oracle isn't going to do that if it breaks on such a trivial thing as this. It must be something really stupid and small, but I'm not seeing it :( Perhaps you should look for a Glassfish forum where you are more likely to find people that use Eclipselink.

    But as long as we're just trying things, try turning the OneToMany property in Groups into a Set in stead of a List. It shouldn't make any difference, but for example Hibernate too has troubles with List properties.
  • 8. Re: Uses a non-entity as target entity
    917543 Newbie
    Currently Being Moderated
    good advise
    thanks for that

    I am trying a last thing before killing myself, I moved to hibernate to test

    however even after amending maven dependency & persistence.xml (+ update glassfish server)
    I got a hibernate error I fixed and now I got back the same error but I don't understand how it's possible to get an EcliseLink error after modifying the persistance.xml

    <?xml version="1.0"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
                   version="2.0">
         <persistence-unit name="chapter02PU" transaction-type="JTA">
              <provider>org.hibernate.ejb.HibernatePersistence</provider>     
              <jta-data-source>jdbc/UnmodDB</jta-data-source>     
              
              <exclude-unlisted-classes>false</exclude-unlisted-classes>
              <properties>
                   <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                   <property name="hibernate.hbm2ddl.auto" value="update"/>
                   <property name="hibernate.show_sql" value="true" />          
    </properties>
         </persistence-unit>
    </persistence>
  • 9. Re: Uses a non-entity as target entity
    gimbal2 Guru
    Currently Being Moderated
    914540 wrote:

    however even after amending maven dependency & persistence.xml (+ update glassfish server)
    I got a hibernate error I fixed and now I got back the same error but I don't understand how it's possible to get an EcliseLink error after modifying the persistance.xml
    What error are you getting exactly? The same one you started the thread with?
  • 10. Re: Uses a non-entity as target entity
    917543 Newbie
    Currently Being Moderated
    Yes it's strange because

    when I comment the oneToMany/ManyToOne parts

    I see hibernate is called

    Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
    INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
    INFO: Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
    INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
    INFO: Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
    INFO: Using provided datasource
    INFO: RDBMS: MySQL, version: 5.5.20
    INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.18 ( Revision: tonci.grgin@oracle.com-20110930151701-jfj14ddfq48ifkfq )
    INFO: Using dialect: org.hibernate.dialect.MySQLDialect
    INFO: Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFactory
    INFO: instantiating TransactionManagerLookup: org.hibernate.transaction.SunONETransactionManagerLookup
    INFO: instantiated TransactionManagerLookup
    INFO: Automatic flush during beforeCompletion(): disabled
    INFO: Automatic session close at end of transaction: disabled
    INFO: JDBC batch size: 15
    INFO: JDBC batch updates for versioned data: disabled
    INFO: Scrollable result sets: enabled

    but when I added the OneToMany/ManyToOne

    I got

    [INFO] Command deploy failed.
    [ERROR] remote failure: Unknown plain text format. A properly formatted response from a PlainTextActionReporter
    [ERROR] always starts with one of these 2 strings: PlainTextActionReporterSUCCESS or PlainTextActionReporterFAILURE. The response we received from the server was not understood: Signature-Version: 1.0
    [ERROR] message: Error occurred during deployment: Exception while preparing t
    [ERROR] he app : Exception [EclipseLink-28018] (Eclipse Persistence Services
    [ERROR] - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.EntityMa
    [ERROR] nagerSetupException
    [ERROR] Exception Description: Predeployment of P
    [ERROR] ersistenceUnit [chapter02PU] failed.
    [ERROR] Internal Exception: Exce
    [ERROR] ption [EclipseLink-7250] (Eclipse Persistence Services - 2.3.0.v20110
    [ERROR] 604-r9504): org.eclipse.persistence.exceptions.ValidationException%%%
    [ERROR] EOL%%%Exception Description: [class com.unmod.Domain.User] uses a non
    [ERROR] -entity [class com.unmod.Domain.Groups] as target entity in the relat
    [ERROR] ionship attribute [field groupe].. Please see server.log for more det
    [ERROR] ails.
    [ERROR] Exception while invoking class org.glassfish.persistenc
    [ERROR] e.jpa.JPADeployer prepare method : javax.persistence.PersistenceExcep
    [ERROR] tion: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2
    [ERROR] .3.0.v20110604-r9504): org.eclipse.persistence.exceptions.EntityManag
    [ERROR] erSetupException
    [ERROR] Exception Description: Predeployment of Pers
    [ERROR] istenceUnit [chapter02PU] failed.
    [ERROR] Internal Exception: Excepti
    [ERROR] on [EclipseLink-7250] (Eclipse Persistence Services - 2.3.0.v20110604
    [ERROR] -r9504): org.eclipse.persistence.exceptions.ValidationException%%%EOL
    [ERROR] %%%Exception Description: [class com.unmod.Domain.User] uses a non-en
    [ERROR] tity [class com.unmod.Domain.Groups] as target entity in the relation
    [ERROR] ship attribute [field groupe].
    [ERROR] Exception [EclipseLink-28018]
    [ERROR] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.p
    [ERROR] ersistence.exceptions.EntityManagerSetupException
    [ERROR] Exception Descripti
    [ERROR] on: Predeployment of PersistenceUnit [chapter02PU] failed.
    [ERROR] Internal E
    [ERROR] xception: Exception [EclipseLink-7250] (Eclipse Persistence Services
    [ERROR] - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.Validati
    [ERROR] onException
    [ERROR] Exception Description: [class com.unmod.Domain.User] uses
    [ERROR] a non-entity [class com.unmod.Domain.Groups] as target entity in the
    [ERROR] relationship attribute [field groupe].

    it's like eclipseLink wanted to bug me over Hibernate.
  • 11. Re: Uses a non-entity as target entity
    917543 Newbie
    Currently Being Moderated
    ok it works now


    and my solution was to move to Hibernate / jboss 7.1

    Thanks for your help
  • 12. Re: Uses a non-entity as target entity
    gimbal2 Guru
    Currently Being Moderated
    That is hardly a solution, more like a gigantic workaround :s I'm sorry you didn't want to take the time to find a proper Glassfish forum and offer the problem there.

    Not that JBoss 7.1 is a bad choice, I prefer it myself.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points