Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Unknown entity type
Unknown entity type [message #478702] Thu, 06 August 2009 12:53 Go to next message
Serge  is currently offline Serge Friend
Messages: 76
Registered: July 2009
Member
Hi,

I have an application with added derby.jar, added eclipselink.jar and
javax.persistence.jar from eclipse eclipselink-2.0.0.v20090731-r4765
installtion zip.
I have entity class and some usage of this class and got different ind
of message when try to use it like:
Exception in thread "main" java.lang.IllegalArgumentException: An
exception occurred while creating a query in EntityManager:
Exception Description: Error compiling the query [select object(o) from
DiscountCode as o]. Unknown entity type [DiscountCode].
///
Caused by: Exception [EclipseLink-8034] (Eclipse Persistence Services -
2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Error compiling the query [select object(o) from
DiscountCode as o]. Unknown entity type [DiscountCode].
///

sometimes (may be with different version of eclipselink I have also
message about missed "@Entity annotation"

What may be wrong?



////////////////////////

my persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
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">
<persistence-unit name="JavaApplication8PU"
transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider >
<class>javaapplication8.DiscountCode</class>
<properties>
<property name="javax.persistence.jdbc.url"
value="jdbc:derby://localhost:1527/sample"/>
<property name="javax.persistence.jdbc.password" value="app"/>
<property name="javax.persistence.jdbc.driver"
value="org.apache.derby.jdbc.ClientDriver"/>
<property name="javax.persistence.jdbc.user" value="app"/>
</properties>
</persistence-unit>
</persistence>

my entity:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package javaapplication8;

import java.io.Serializable;
import java.math.BigDecimal;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
*
* @author sp153251
*/
@Entity
@Table(name = "DISCOUNT_CODE")
@NamedQueries({@NamedQuery(name = "DiscountCode.findAll", query =
"SELECT d FROM DiscountCode d"), @NamedQuery(name =
"DiscountCode.findByDiscountCode", query = "SELECT d FROM DiscountCode d
WHERE d.discountCode = :discountCode"), @NamedQuery(name =
"DiscountCode.findByRate", query = "SELECT d FROM DiscountCode d WHERE
d.rate = :rate")})
public class DiscountCode implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "DISCOUNT_CODE")
private Character discountCode;
@Column(name = "RATE")
private BigDecimal rate;

public DiscountCode() {
}

public DiscountCode(Character discountCode) {
this.discountCode = discountCode;
}

public Character getDiscountCode() {
return discountCode;
}

public void setDiscountCode(Character discountCode) {
this.discountCode = discountCode;
}

public BigDecimal getRate() {
return rate;
}

public void setRate(BigDecimal rate) {
this.rate = rate;
}

@Override
public int hashCode() {
int hash = 0;
hash += (discountCode != null ? discountCode.hashCode() : 0);
return hash;
}

@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id
fields are not set
if (!(object instanceof DiscountCode)) {
return false;
}
DiscountCode other = (DiscountCode) object;
if ((this.discountCode == null && other.discountCode != null)
|| (this.discountCode != null &&
!this.discountCode.equals(other.discountCode))) {
return false;
}
return true;
}

@Override
public String toString() {
return "javaapplication8.DiscountCode[discountCode=" +
discountCode + "]";
}

}
Unknown entity type - addl details [message #478741 is a reply to message #478702] Thu, 06 August 2009 15:44 Go to previous messageGo to next message
Serge  is currently offline Serge Friend
Messages: 76
Registered: July 2009
Member
- javax.persisten.jar is for jpa 2.0

- if I replace eclipselink with either toplink or hibernate(not sure
with version) all works. i.e. add toplink/hibernate libraries and
replace provider/properties in persistence.xml.
Re: Unknown entity type - addl details [message #478819 is a reply to message #478741] Fri, 07 August 2009 06:47 Go to previous messageGo to next message
Thomas Haskes is currently offline Thomas HaskesFriend
Messages: 147
Registered: July 2009
Senior Member
Did you try listing your entity classes in persistence xml?

To do that you need to add a "class" child to your persistnce xml before
the <properties> child like this.

<persistence-unit name="some_pu" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider >

<class>org.package.[...].DiscountCode</class>
<class>org.package.SomeOtherClass</class>
<properties>
<property name="eclipselink.jdbc.driver"
value="oracle.jdbc.driver.OracleDriver" />
[...]

I remember that when I switched to EL from Hibernate that I had to list
my classes as EL whas complaining about not knowing my entites. That
helped. EL seems to be more strict concerning unlisted entites as other
ORM's.

Later,

Tom

Serge schrieb:
> - javax.persisten.jar is for jpa 2.0
>
> - if I replace eclipselink with either toplink or hibernate(not sure
> with version) all works. i.e. add toplink/hibernate libraries and
> replace provider/properties in persistence.xml.
Re: Unknown entity type - addl details [message #478820 is a reply to message #478819] Fri, 07 August 2009 06:59 Go to previous messageGo to next message
Serge  is currently offline Serge Friend
Messages: 76
Registered: July 2009
Member
Thomas Haskes пишет:
> Did you try listing your entity classes in persistence xml?

see my persistence.xml in first message, it contain
<class>javaapplication8.DiscountCode</class>

I tried also to add <exclude-unlisted-classes> and still no success.
Wonder if it's an issue in eclipselink 2.0 m6, may be usage of jpa 2.0
javax (from eclipselink bundle) affect this too.

>
> To do that you need to add a "class" child to your persistnce xml before
> the <properties> child like this.
>
> <persistence-unit name="some_pu" transaction-type="RESOURCE_LOCAL">
> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider >
>
> <class>org.package.[...].DiscountCode</class>
> <class>org.package.SomeOtherClass</class>
> <properties>
> <property name="eclipselink.jdbc.driver"
> value="oracle.jdbc.driver.OracleDriver" />
> [...]
>
> I remember that when I switched to EL from Hibernate that I had to list
> my classes as EL whas complaining about not knowing my entites. That
> helped. EL seems to be more strict concerning unlisted entites as other
> ORM's.
>
> Later,
>
> Tom
>
> Serge schrieb:
>> - javax.persisten.jar is for jpa 2.0
>>
>> - if I replace eclipselink with either toplink or hibernate(not sure
>> with version) all works. i.e. add toplink/hibernate libraries and
>> replace provider/properties in persistence.xml.
Re: Unknown entity type - addl details [message #478844 is a reply to message #478820] Fri, 07 August 2009 07:39 Go to previous messageGo to next message
Thomas Haskes is currently offline Thomas HaskesFriend
Messages: 147
Registered: July 2009
Senior Member
> see my persistence.xml in first message, it contain
> <class>javaapplication8.DiscountCode</class>
>

Sorry didn't see that.
eclipse link 2.0.0 + j2se + derby [message #478891 is a reply to message #478844] Fri, 07 August 2009 11:27 Go to previous messageGo to next message
Serge  is currently offline Serge Friend
Messages: 76
Registered: July 2009
Member
Thomas Haskes пишет:
>> see my persistence.xml in first message, it contain
>> <class>javaapplication8.DiscountCode</class>
>>
>
> Sorry didn't see that.

It's ok.

but may be another question have anybody tried to use eclipse link 2.0.0
with j2se applications?
eclipse link 2.0.0 + j2se + derby - issue? [message #480659 is a reply to message #478891] Tue, 18 August 2009 07:08 Go to previous messageGo to next message
Serge  is currently offline Serge Friend
Messages: 76
Registered: July 2009
Member
> but may be another question have anybody tried to use eclipse link 2.0.0
> with j2se applications?

for reference: next issue was filed
https://bugs.eclipse.org/bugs/show_bug.cgi?id=286087
Re: Unknown entity type [message #480868 is a reply to message #478702] Tue, 18 August 2009 17:54 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

This is an odd error, it seems your classpath may be corrupt, or have
issues. Are you in a basic JSE environment, or are you using something
like Spring or OSGI?

EclipseLink 2.0 has been extensively tested in a JSE environment, so there
is something wrong with your configuration. Is your persistence unit in a
jar? It should be deployed in a jar with the persistence.xml in the
META-INF directory and the entity classes inside their correct packages in
the jar.

Your error says, "select object(o) from DiscountCode as o"

But your code has, "SELECT d FROM DiscountCode d"

So it seems your have your classes on the classpath twice, or something is
corrupt in your environment.

Perhaps try one of the EclipseLink examples first.

---
James


James : Wiki : Book : Blog : Twitter
Re: Unknown entity type [message #480893 is a reply to message #480868] Tue, 18 August 2009 19:21 Go to previous messageGo to next message
Serge  is currently offline Serge Friend
Messages: 76
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------000006040606040108020304
Content-Type: text/plain; charset=KOI8-R; format=flowed
Content-Transfer-Encoding: 8bit

James
Re: Unknown entity type [message #481110 is a reply to message #480868] Wed, 19 August 2009 16:14 Go to previous messageGo to next message
Serge  is currently offline Serge Friend
Messages: 76
Registered: July 2009
Member
James пишет:

> Perhaps try one of the EclipseLink examples first.

Can you point me to some examples with complete configuration steps?

For example
1. I found some config on
http://wiki.eclipse.org/Configuring_a_EclipseLink_JPA_Applic ation_(ELUG)

but it says only about eclipse.jar but this one jar do not contain
jpa2.0 api.

2. there are eclipselink.jar and persistence.jar on
http://wiki.eclipse.org/EclipseLink/Examples/JPA/JSF_Tutoria l
and
http://wiki.eclipse.org/EclipseLink/Examples/JPA/RCP

but eclpselink.zip (2.0.0 M6) (installation archive) do not contain
persistence.jar, I'm using javax.persistence_2.0_preview.jar instead.

Sergey

>
> ---
> James
>
>
issue for packages like "javasomething" [message #488002 is a reply to message #480659] Fri, 25 September 2009 09:25 Go to previous message
Serge  is currently offline Serge Friend
Messages: 76
Registered: July 2009
Member
Serge пишет:
>
>> but may be another question have anybody tried to use eclipse link
>> 2.0.0 with j2se applications?
>
> for reference: next issue was filed
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=286087

some details from issue in subj, hope will be fixed in 2.0
Previous Topic:criteria API: select count(*) from ..
Next Topic:not support executeThreadRuntime
Goto Forum:
  


Current Time: Sun Dec 21 09:17:50 GMT 2014

Powered by FUDForum. Page generated in 0.19462 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software