wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Hibernate - TABLE is not mapped Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate - TABLE is not mapped" Watch "Hibernate - TABLE is not mapped" New topic
Author

Hibernate - TABLE is not mapped

Alessandro Ilardo
Ranch Hand

Joined: Dec 23, 2005
Posts: 218
Hi guys,
I'm stuck with this error,
(from the client)

11:36:14,666DEBUG SecurityAssociation:143 - Using ThreadLocal: false
11:36:14,715DEBUG Client:514 - invoke called, but our invoker is disconnected, discarding and fetching another fresh invoker for: InvokerLocator [socket://127.0.0.2:3873/]
11:36:14,715DEBUG SocketClientInvoker:275 - connect called for: org.jboss.remoting.transport.socket.SocketClientInvoker@15d56d5
javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: USR is not mapped [SELECT DISTINCT OBJECT(k) FROM USR k WHERE k.username = ?1]
...

Caused by: org.hibernate.hql.ast.QuerySyntaxException: USR is not mapped [SELECT DISTINCT OBJECT(k) FROM USR k WHERE k.username = ?1]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)


My EJB3 method


Persistence.xml


I'm using annotations


and JBoss 4.1 - NetBeans 5.5 - MySql 5

What's wrong?
Thanks


trying to decode a woman mind....
Alessandro Ilardo
Ranch Hand

Joined: Dec 23, 2005
Posts: 218
I'm trying some test, like: em.persist(user);

and I get this
javax.ejb.EJBException: java.lang.IllegalArgumentException: Unknown entity: eu.virtualLab.users.model.Usr

Do I need a mapping file even if I'm using annotations?

And to be onest, I expected Hibernate to create the table for me, but it didn't. What's wrong?
[ March 10, 2007: Message edited by: Alessandro Ilardo ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Hibernate does not do those things on its own. It needs to be told to do that.

Now you have your DataSource and your creation of the tables with

<jta-data-source>java:/MySqlDS</jta-data-source>

and

<property name="hibernate.hbm2ddl.auto" value="create-drop"/>

Good, maybe you are getting an exception higher in your starting of your app server and don't see that exception that either it can't find the datasource in the lookup, or it had an exception when trying to create the datasource, again in the App Server.


So for detecting the Mapped Files you need to add the following to your persistence.xml

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

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Alessandro Ilardo
Ranch Hand

Joined: Dec 23, 2005
Posts: 218
Thanks Mark for your reply, last night I made some progress and I forgot to update the thread which was opened.
I don't receive any error message from JBoss init

11:18:12,103 INFO [JmxKernelAbstraction] installing MBean: persistence.units:jar=Users-EJBModule.jar,unitName=Users-EJBModulePU with dependencies:
11:18:12,104 INFO [JmxKernelAbstraction] jboss.jca:name=MySqlDS,service=DataSourceBinding
11:18:12,154 INFO [Version] Hibernate EntityManager 3.2.0.GA
11:18:12,184 INFO [Version] Hibernate Annotations 3.2.0.GA
11:18:12,199 INFO [Environment] Hibernate 3.2.0.ga
11:18:12,209 INFO [Environment] hibernate.properties not found
11:18:12,212 INFO [Environment] Bytecode provider name : javassist
11:18:12,219 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
11:18:12,376 WARN [Ejb3Configuration] Persistence provider caller does not implements the EJB3 spec correctly. PersistenceUnitInfo.getNewTempClassLoader() is null.
11:18:12,471 INFO [Configuration] Reading mappings from resource: META-INF/orm.xml
11:18:12,475 INFO [Ejb3Configuration] [PersistenceUnit: Users-EJBModulePU] no META-INF/orm.xml found
11:18:12,585 INFO [AnnotationBinder] Binding entity from annotated class: eu.virtualLab.users.model.Usr
11:18:12,663 INFO [EntityBinder] Bind entity eu.virtualLab.users.model.Usr on table USR
11:18:13,132 INFO [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
11:18:13,141 INFO [InjectedDataSourceConnectionProvider] Using provided datasource
11:18:13,338 INFO [SettingsFactory] RDBMS: MySQL, version: 5.0.18
11:18:13,339 INFO [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.0.11-stable ( $Date: 2004/02/04 02:47:36 $, $Revision: 1.27.2.34 $ )
11:18:13,376 INFO [Dialect] Using dialect: org.hibernate.dialect.MySQL5Dialect
11:18:13,387 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFactory
11:18:13,394 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
11:18:13,400 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
11:18:13,401 INFO [SettingsFactory] Automatic flush during beforeCompletion(): disabled
11:18:13,401 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
11:18:13,401 INFO [SettingsFactory] JDBC batch size: 15
11:18:13,401 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
11:18:13,403 INFO [SettingsFactory] Scrollable result sets: enabled
11:18:13,403 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
11:18:13,403 INFO [SettingsFactory] Connection release mode: auto
11:18:13,407 INFO [SettingsFactory] Maximum outer join fetch depth: 2
11:18:13,407 INFO [SettingsFactory] Default batch fetch size: 1
11:18:13,407 INFO [SettingsFactory] Generate SQL with comments: disabled
11:18:13,408 INFO [SettingsFactory] Order SQL updates by primary key: disabled
11:18:13,408 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
11:18:13,415 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
11:18:13,416 INFO [SettingsFactory] Query language substitutions: {}
11:18:13,416 INFO [SettingsFactory] JPA-QL strict compliance: enabled
11:18:13,416 INFO [SettingsFactory] Second-level cache: enabled
11:18:13,416 INFO [SettingsFactory] Query cache: disabled
11:18:13,418 INFO [SettingsFactory] Cache provider: org.hibernate.cache.HashtableCacheProvider
11:18:13,423 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
11:18:13,424 INFO [SettingsFactory] Structured second-level cache entries: disabled
11:18:13,442 INFO [SettingsFactory] Echoing all SQL to stdout
11:18:13,443 INFO [SettingsFactory] Statistics: disabled
11:18:13,443 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
11:18:13,447 INFO [SettingsFactory] Default entity-mode: pojo
11:18:13,512 INFO [SessionFactoryImpl] building session factory
11:18:14,652 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
11:18:14,723 INFO [SchemaExport] Running hbm2ddl schema export
11:18:14,728 INFO [SchemaExport] exporting generated schema to database
11:18:14,885 INFO [SchemaExport] schema export complete
11:18:14,954 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming rg.jnp.interfaces}
11:18:15,176 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=Users-EJBModule.jar,name=UsrSessionBean,service=EJB3 with dependencies:
11:18:15,177 INFO [JmxKernelAbstraction] persistence.units:jar=Users-EJBModule.jar,unitName=Users-EJBModulePU
11:18:16,282 INFO [EJBContainer] STARTED EJB: eu.virtualLab.users.UsrSessionBean ejbName: UsrSessionBean
11:18:16,390 INFO [EJB3Deployer] Deployed: file:/etc/jboss-4.0.5.GA/server/default/deploy/Users-EJBModule.jar

and now the table is correctly created at deploy time. the error, was in the query,
this lookup query now works fine

I was using USR which is the table name, but it requiered the class name.

I'm now facing another issue:

javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.PropertyValueException:
not-null property references a null or transient value: eu.virtualLab.users.model.Usr.password

the facade bean:
//add user to database
logger.info("[addUsr] password value? -> "+password);
Usr user = new Usr(username,password,_role,_name,surname,companyName,vat,
address,city,postcode,country,email,phone,false);
em.persist(user);

The POJO
@Column(name="password", nullable=false)
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}

The password parameter is not empty (it is shown by the logger), so where is my mistake now?

Thanks in advance.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

While the parameter might not be null, it seems the class attribute is null when it goes to persist.

So my question is what does the constructor that takes

new Usr(username,password,_role,_name,surname,companyName,vat,
address,city,postcode,country,email,phone,false);


Look like? Does it correctly set the instances password variable?

Mark
Alessandro Ilardo
Ranch Hand

Joined: Dec 23, 2005
Posts: 218

Mark, you were write, I didn't notice that the parameter name didn't match the other param sent to the setPassword method.
It's a such of small mistake, but quite frequent, so I guess I need to pay more attention. But thank you anyway, you probably avoid me to spend half day trying to figure it out.

Have a good day.
Thank you again.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Originally posted by Alessandro Ilardo:

Mark, you were write, I didn't notice that the parameter name didn't match the other param sent to the setPassword method.
It's a such of small mistake, but quite frequent, so I guess I need to pay more attention. But thank you anyway, you probably avoid me to spend half day trying to figure it out.

Have a good day.
Thank you again.


Yep, I do it all the time too. The simplest mistakes always seem to take the longest to solve for some reason.

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Hibernate - TABLE is not mapped
 
Similar Threads
Exception while deploying the bean
Problem javax.persistence.NoResultException: No entity found for query
no error but entity is not persisted
Error in LookUP in JBOSS 5.0.0.Beta4 EJB3.0
Hibernate -> not-null property references a null or transient value