-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Why isn't Ejb3Configuration finding my annotated classes??
PostPosted: Wed May 02, 2007 11:49 am 
Newbie

Joined: Wed Mar 21, 2007 2:07 pm
Posts: 9
Location: Minnesota
Version of Hibernate: 3.2
INFO 02-05 10:06:45,786 (Version.java:<clinit>:15) -Hibernate EntityManager 3.2.0.CR1
INFO 02-05 10:06:45,802 (Version.java:<clinit>:15) -Hibernate Annotations 3.2.0.CR1
INFO 02-05 10:06:45,802 (Environment.java:<clinit>:499) -Hibernate 3.2 cr2

Mapping documents: annotated classes (generated by Hibernate Tools)
domain code located in: <workdir>/src/java/com/abc/greta/test/dataObjects/DemoTable.java

persistence.xml located in: <workdir>/bin/META-INF/persistence.xml

I'm getting the following exception:

Code:
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.hql.ast.QuerySyntax
Exception: DemoTable is not mapped [from DemoTable t order by t.name desc]
   at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.
java:567)
   at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:79)



My persistence.xml:

Code:

<persistence-unit name="demotest" transaction-type="RESOURCE_LOCAL">
    <properties>
      <property name="hibernate.archive.autodetection" value="class, hbm"/>
           
      <property name="hibernate.connection.driver_class"
        value="oracle.jdbc.driver.OracleDriver" />
      <property name="hibernate.default_schema" value="GRETA" />
      <property name="hibernate.connection.username" value="greta" />
      <property name="hibernate.connection.password" value="greta" />
      <property name="hibernate.connection.url"
        value="jdbc:oracle:thin:@localhost:tactical" />
      <property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
      <property name="hibernate.connection.autocommit">false</property>
     
      <property name="hibernate.max_fetch_depth" value="3"/>
     
      <property name="hibernate.query.factory_class"
        value="org.hibernate.hql.ast.ASTQueryTranslatorFactory" />
       
      <property name="hibernate.show_sql" value="true" />
      <property name="hibernate.format_sql" value="true" />
     
      <property name="hibernate.cache.provider_class"
        value="org.hibernate.cache.NoCacheProvider" />
    </properties>
  </persistence-unit>
 
</persistence>


Code:
package com.abc.greta.test.dataObjects;

// Generated May 2, 2007 10:05:23 AM by Hibernate Tools 3.2.0.b9

import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.SEQUENCE;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
* DemoRadar generated by hbm2java
*/
@Entity
@Table(name = "DEMO_TABLE")
public class DemoTable implements java.io.Serializable {

    private Integer Id;
    private String name;
    private String description;
    private Date datetime;
    private Boolean simulated;

    public DemoRadar() {
    }

    public DemoRadar(String name) {
        this.name = name;
    }

    public DemoRadar(String name,
            String description, Date datetime,
            Boolean simulated) {
        this.name = name;
        this.description = description;
        this.datetime = datetime;
        this.simulated = simulated;
    }

    @SequenceGenerator(name = "generator")
    @Id
    @GeneratedValue(strategy = SEQUENCE, generator = "generator")
    @Column(name = "ID", nullable = false, precision = 22, scale = 0)
    public Integer getId() {
        return this.Id;
    }

    public void setRadarId(Integer Id) {
        this.Id = Id;
    }

    @Column(name = "NAME", unique = true, nullable = false, length = 10)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "DESCRIPTION", length = 200)
    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column(name = "DATETIME")
    public Date getDatetime() {
        return this.datetime;
    }

    public void setDatetime(Date datetime) {
        this.datetime = datetime;
    }

    @Column(name = "SIMULATED", length = 1)
    public Boolean isSimulated() {
        return this.simulated;
    }

    public void setSimulated(Boolean simulated) {
        this.simulated = simulated;
    }

}


Code:
    @SuppressWarnings("unchecked")
    public Vector<DemoTable> getDemoTables() {
        Vector<DemoTable> demoTables = null;
       
        demoTables = (Vector<DemoRadar>) em.createQuery("from DemoTable t " +
                "order by t.name desc")
                .getResultList();

        return demoTables;
    }


I can not figure this out!! Driving me nuts!! Why isn't Ejb3Configuration finding my annotated classes?????

Possible useful debug information (from before the exception):

Code:
INFO  02-05 10:06:45,833 (Environment.java:<clinit>:532)  -hibernate.properties not found
INFO  02-05 10:06:45,833 (Environment.java:buildBytecodeProvider:666)  -Bytecode provider name : cgl
ib
INFO  02-05 10:06:45,833 (Environment.java:<clinit>:583)  -using JDK 1.4 java.sql.Timestamp handling
DEBUG 02-05 10:06:45,928 (Ejb3Configuration.java:createEntityManagerFactory:165)  -Trying to find pe
rsistence unit: demotest
DEBUG 02-05 10:06:45,928 (Ejb3Configuration.java:createEntityManagerFactory:174)  -Analyse of persis
tence.xml: file:/D:/workspace/bin/META-INF/persistence.xml
DEBUG 02-05 10:06:46,226 (PersistenceXmlLoader.java:parsePersistenceUnit:115)  -Persistent Unit name
from persistence.xml: demotest
DEBUG 02-05 10:06:46,226 (Ejb3Configuration.java:getDetectedArtifacts:476)  -Detect class: true; det
ect hbm: false
DEBUG 02-05 10:06:46,226 (Ejb3Configuration.java:createEntityManagerFactory:186)  -Archive to be pro
cessed by hibernate Entity Manager implementation found
DEBUG 02-05 10:06:46,226 (JarVisitor.java:unqualify:185)  -Searching mapped entities in jar/par: fil
e:/D:/workspace/bin
DEBUG 02-05 10:06:46,226 (Ejb3Configuration.java:createEntityManagerFactory:193)  -Persistence unit
name: demotest
DEBUG 02-05 10:06:46,226 (Ejb3Configuration.java:createEntityManagerFactory:195)  -emname:demotest metadata: demotest
FATAL 02-05 10:06:46,258 (Ejb3Configuration.java:accept:514)  -META-INF/persistence.xmlO:Ofalse
DEBUG 02-05 10:06:46,258 (Ejb3Configuration.java:createFactory:124)  -Creating Factory: demotest
WARN  02-05 10:06:46,258 (Ejb3Configuration.java:prepareProperties:875)  -Defining hibernate.transac
tion.flush_before_completion=true ignored in HEM
DEBUG 02-05 10:06:46,258 (AnnotationConfiguration.java:secondPassCompile:232)  -Execute first pass m
apping processing
DEBUG 02-05 10:06:46,305 (AnnotationConfiguration.java:processArtifactsOfType:336)  -Process hbm fil
es
DEBUG 02-05 10:06:46,305 (AnnotationConfiguration.java:processArtifactsOfType:344)  -Process annotat
ed classes
DEBUG 02-05 10:06:46,305 (AnnotationConfiguration.java:secondPassCompile:282)  -processing manytoone
fk mappings
DEBUG 02-05 10:06:46,305 (Configuration.java:secondPassCompile:1039)  -processing extends queue
DEBUG 02-05 10:06:46,305 (Configuration.java:secondPassCompile:1043)  -processing collection mapping
s
DEBUG 02-05 10:06:46,305 (Configuration.java:secondPassCompile:1054)  -processing native query and R
esultSetMapping mappings
DEBUG 02-05 10:06:46,305 (Configuration.java:secondPassCompile:1062)  -processing association proper
ty references
DEBUG 02-05 10:06:46,305 (Configuration.java:secondPassCompile:1084)  -processing foreign key constr
aints
WARN  02-05 10:06:46,321 (Ejb3Configuration.java:createEntityManagerFactory:756)  -hibernate.connect
ion.autocommit = false break the EJB3 specification
DEBUG 02-05 10:06:46,321 (Configuration.java:buildSessionFactory:1204)  -Preparing to build session
factory with filters : {}
DEBUG 02-05 10:06:46,321 (AnnotationConfiguration.java:secondPassCompile:232)  -Execute first pass m
apping processing
DEBUG 02-05 10:06:46,321 (AnnotationConfiguration.java:processArtifactsOfType:336)  -Process hbm fil
es
DEBUG 02-05 10:06:46,321 (AnnotationConfiguration.java:processArtifactsOfType:344)  -Process annotat
ed classes
DEBUG 02-05 10:06:46,321 (AnnotationConfiguration.java:secondPassCompile:282)  -processing manytoone
fk mappings
DEBUG 02-05 10:06:46,321 (Configuration.java:secondPassCompile:1039)  -processing extends queue
DEBUG 02-05 10:06:46,321 (Configuration.java:secondPassCompile:1043)  -processing collection mapping
s
DEBUG 02-05 10:06:46,321 (Configuration.java:secondPassCompile:1054)  -processing native query and R
esultSetMapping mappings
DEBUG 02-05 10:06:46,321 (Configuration.java:secondPassCompile:1062)  -processing association proper
ty references
DEBUG 02-05 10:06:46,321 (Configuration.java:secondPassCompile:1084)  -processing foreign key constr
aints


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 12:08 pm 
Newbie

Joined: Wed Mar 21, 2007 2:07 pm
Posts: 9
Location: Minnesota
I still haven't solved this problem (I currently have to specify all my annotated classes in my persistence.xml file). Do the annotated classes have to be in a jar file for Ejb3Configuration to find them?

My annotated *.class files are in: ./classes/*.class
My persistence.xml file is in: ./bin/META-INF/persistence.xml
./classes/ is on my class path.

Any help would be appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 5:57 pm 
Newbie

Joined: Fri May 11, 2007 5:51 pm
Posts: 1
Location: Arlington, VA
You need something like this in your hibernate.cfg.xml

Code:
<mapping class="com.mycompany.blah.pojos.MyPOJO" />


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 10:33 am 
Newbie

Joined: Wed Mar 21, 2007 2:07 pm
Posts: 9
Location: Minnesota
Yes, that does fix the problem but JPA is supposed to have an autodetection feature where it should be able to find your annotated classes without having to list them in the persistence.xml file.

The JPA persistence provider should try and find the annotated classes in the build output directory (according to the Java Persistence book).

For hibernate, you are supposed to include the following property to turn on autodetection:

Code:
<property name="hibernate.archive.autodetection" value="class"/>


This does not work for me and I'm not sure why. It only works if I specify the mappings (as was suggested).


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 11:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
probably because your META-INF/persistence.xml is not in the same dir/path as your domain classes.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 3:00 pm 
Newbie

Joined: Wed Mar 21, 2007 2:07 pm
Posts: 9
Location: Minnesota
Thanks! That fixed my problem.

I'm using Eclipse and in my .classpath file I had the parent directory of META-INF marked as

kind="lib"

instead of

kind="src".

When I changed it to "src" everything worked.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.