-->
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.  [ 2 posts ] 
Author Message
 Post subject: Using classes in another directory
PostPosted: Mon Oct 24, 2011 10:08 pm 
Newbie

Joined: Mon Jul 21, 2008 5:40 am
Posts: 16
Hi,

I have following code to access a database, the Photo.class is in another directory, but I alway get this error:

java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Photo is not mapped [from Photo]

code in Groovy:

emf = Persistence.createEntityManagerFactory("default")
em = emf.createEntityManager()
em.getTransaction().begin()
def books = em.createQuery("from Photo").getResultList()

persistence.xml:

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/ ... ce_1_0.xsd"
version="1.0">
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<jar-file>file:/sample/target/classes</jar-file>
<class>org.sample.entities.Photo</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/sample" />
<property name="hibernate.connection.username" value="sample" />
<property name="hibernate.connection.password" value="abc" />

</properties>
</persistence-unit>
</persistence>

log:

2 [main] INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.5.6-Final
29 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.6-Final
32 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
39 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
47 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
170 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
184 [main] INFO org.hibernate.ejb.Version - Hibernate EntityManager 3.5.6-Final
1182 [main] INFO org.hibernate.cfg.AnnotationConfiguration - Hibernate Validator not found: ignoring
1238 [main] INFO org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
1250 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
1251 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
1251 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: true
1272 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/sample
1272 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=sample, password=****, autocommit=true, release_mode=auto}
1889 [main] INFO org.hibernate.cfg.SettingsFactory - RDBMS: MySQL, version: 5.1.45
1890 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} )
1928 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
1977 [main] INFO org.hibernate.engine.jdbc.JdbcSupportLoader - Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
1981 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
1985 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
1985 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
1985 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
1985 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
1986 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
1990 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
1990 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
1990 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
1992 [main] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
1992 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
1992 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
1992 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
1992 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
1992 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2003 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
2003 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
2003 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: enabled
2004 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
2004 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
2004 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
2004 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
2004 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
2021 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
2022 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
2022 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
2022 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
2022 [main] INFO org.hibernate.cfg.SettingsFactory - Check Nullability in Core (should be disabled when Bean Validation is on): enabled
2090 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
2114 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
Caught: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Photo is not mapped [from Photo]
at test3.run(test3.groovy:44)


Top
 Profile  
 
 Post subject: Re: Using classes in another directory
PostPosted: Thu Oct 27, 2011 4:06 pm 
Newbie

Joined: Mon May 11, 2009 8:42 am
Posts: 5
Hibernate says your Photo class isn't mapped, i.e. it doesn't know what database table the Photo class maps to because you didn't provide that information. Since you are using JPA, this is usually done by annotating the class, and adding an entry for it in the persistence.xml file. The Hibernate documentation has good tutorial information on this here http://docs.jboss.org/hibernate/core/3.6/quickstart/en-US/html/hibernate-gsg-tutorial-jpa.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.