-->
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.  [ 9 posts ] 
Author Message
 Post subject: Stupid Problem
PostPosted: Thu Oct 20, 2005 12:42 pm 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:35 pm
Posts: 21
Hi,

For a couple of days now, I'm trying to learn my way into Hibernate. I finally got one of the examples running, AND IT WORKED, partially.

I can insert stuff into my database table, but the when i try to retrieve all of them, it just doesn't return any result. Altough the code looks right to me ...

----code

tx = session.beginTransaction();
Query query = session.createQuery("select honey.id, honey.name from honey");
System.out.println(query.getQueryString());
Iterator it = query.list().iterator();
while ( it.hasNext() ) {
Honey honey = (Honey) it.next();
System.out.println("Id " + honey.getId() + " Name " + honey.getName() );
}

// [laliluna] commit your transaction or nothing is wrote to the db
tx.commit();

// [laliluna] clean up (close the session)
session.close();

---- /code


The logger reports all kinds of stuff, but i pressumed this was irrelevant to my problem because i could already insert stuff, so retrieving shouldnt be a problem ...



--- Logger:
0 [main] INFO TestClient - creating honey
149 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.1 rc2
155 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
162 [main] INFO org.hibernate.cfg.Environment - using CGLIB reflection optimizer
164 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
247 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
248 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
586 [main] ERROR org.hibernate.util.DTDEntityResolver - Don't use old DTDs, read the Hibernate 3.x Migration Guide!
1037 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource: de/laliluna/example/Honey.hbm.xml
1041 [main] ERROR org.hibernate.util.DTDEntityResolver - Don't use old DTDs, read the Hibernate 3.x Migration Guide!
2018 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: de.laliluna.example.Honey -> honey
2047 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
2047 [main] INFO org.hibernate.cfg.Configuration - processing extends queue
2047 [main] INFO org.hibernate.cfg.Configuration - processing collection mappings
2047 [main] INFO org.hibernate.cfg.Configuration - processing association property references
2048 [main] INFO org.hibernate.cfg.Configuration - processing foreign key constraints
2224 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
2224 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
2225 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
2230 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/firsthibernate
2230 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=root, password=****}
2749 [main] INFO org.hibernate.cfg.SettingsFactory - RDBMS: MySQL, version: 4.0.25
2750 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.11 ( $Date: 2005-09-21 18:20:03 +0000 (Wed, 21 Sep 2005) $, $Revision: 4287 $ )
2778 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
2785 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
2788 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2788 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
2789 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
2789 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
2790 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
2791 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
2792 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
2792 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
2794 [main] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
2794 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
2795 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
2795 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
2796 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2799 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
2800 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
2800 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
2801 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
2801 [main] INFO org.hibernate.cfg.SettingsFactory - Cache provider: org.hibernate.cache.EhCacheProvider
2805 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
2805 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
2812 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
2812 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
2813 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: POJO
3018 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
3029 [main] WARN net.sf.ehcache.config.Configurator - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/home/kidon/hibernate-3.1/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
3239 [main] ERROR org.hibernate.proxy.BasicLazyInitializer - CGLIB Enhancement failed: de.laliluna.example.Honey
java.lang.NoSuchMethodError: net.sf.cglib.proxy.Enhancer.setInterceptDuringConstruction(Z)V
at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:96)
at org.hibernate.proxy.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:41)
at org.hibernate.tuple.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:161)
at org.hibernate.tuple.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:131)
at org.hibernate.tuple.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.TuplizerLookup.create(TuplizerLookup.java:64)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:249)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:411)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:108)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:217)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1145)
at de.laliluna.example.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:49)
at de.laliluna.example.TestClient.createHoney(TestClient.java:38)
at de.laliluna.example.TestClient.main(TestClient.java:20)
3242 [main] WARN org.hibernate.tuple.PojoEntityTuplizer - could not create proxy factory for:de.laliluna.example.Honey
org.hibernate.HibernateException: CGLIB Enhancement failed: de.laliluna.example.Honey
at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:107)
at org.hibernate.proxy.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:41)
at org.hibernate.tuple.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:161)
at org.hibernate.tuple.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:131)
at org.hibernate.tuple.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.TuplizerLookup.create(TuplizerLookup.java:64)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:249)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:411)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:108)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:217)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1145)
at de.laliluna.example.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:49)
at de.laliluna.example.TestClient.createHoney(TestClient.java:38)
at de.laliluna.example.TestClient.main(TestClient.java:20)
Caused by: java.lang.NoSuchMethodError: net.sf.cglib.proxy.Enhancer.setInterceptDuringConstruction(Z)V
at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:96)
... 14 more
3435 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
3436 [main] INFO org.hibernate.impl.SessionFactoryImpl - Checking 0 named queries
primary key is 16
3521 [main] INFO TestClient - updating honey
3535 [main] INFO TestClient - listing honey[code][/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 2:12 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
well, there is a few things you need to change:

Code:
Query query = session.createQuery("select honey.id, honey.name from honey");


can be changed to just
Code:
Query query = session.createQuery("from Honey");



also
Code:
586 [main] ERROR org.hibernate.util.DTDEntityResolver - Don't use old DTDs, read the Hibernate 3.x Migration Guide!

means you should change the top of your hbm files to point to the correct dtds, which is
Code:
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >


and
Code:
java.lang.NoSuchMethodError: net.sf.cglib.proxy.Enhancer.setInterceptDuringConstruction(Z)V


leads me to believe you forgot to include the new version of cglib on your classpath or you have duplicate versions of it.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 2:12 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
change "select honey.id, honey.name from honey" to "from honey" if the name of the class is com.foo.honey .

if your class is named honey, you may want to name this to Honey .


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 5:03 pm 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:35 pm
Posts: 21
OK, thx in advance for the quick response

U were partially right, i used old DTD's, so i fixed that problem. A little question about your cglib suggestion. I started out with another cglib file, but it kept trapping. So i did some searching, ans found out that i needed to use cglib-full.jar

So i removed the other cglib file, and added the new one. Is this correct ?

Still i get absolutely no results for my query, its seems like it just doesnt return any results, because i tested whether the program entered the while loop, and it just doesn't, so the iterator says "pointing to an empty list".

I really don't get it, one should expect when inserting goes well, retrieving wouldn't be a problem either...




a look at the new output:

---log4j

0 [main] INFO TestClient - creating honey
197 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.1 rc2
203 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
210 [main] INFO org.hibernate.cfg.Environment - using CGLIB reflection optimizer
212 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
294 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
295 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
675 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource: de/laliluna/example/Honey.hbm.xml
1082 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: de.laliluna.example.Honey -> honey
1112 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
1113 [main] INFO org.hibernate.cfg.Configuration - processing extends queue
1113 [main] INFO org.hibernate.cfg.Configuration - processing collection mappings
1114 [main] INFO org.hibernate.cfg.Configuration - processing association property references
1114 [main] INFO org.hibernate.cfg.Configuration - processing foreign key constraints
1234 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
1234 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
1235 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
1246 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/firsthibernate
1246 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=root, password=****}
1556 [main] INFO org.hibernate.cfg.SettingsFactory - RDBMS: MySQL, version: 4.0.25
1557 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.11 ( $Date: 2005-09-21 18:20:03 +0000 (Wed, 21 Sep 2005) $, $Revision: 4287 $ )
1634 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
1705 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
1708 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
1708 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
1709 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
1709 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
1710 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
2109 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
2110 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
2110 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
2111 [main] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
2112 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
2112 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
2113 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
2113 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2117 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
2117 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
2118 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
2118 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
2119 [main] INFO org.hibernate.cfg.SettingsFactory - Cache provider: org.hibernate.cache.EhCacheProvider
2122 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
2123 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
2129 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
2130 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
2130 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: POJO
2527 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
2537 [main] WARN net.sf.ehcache.config.Configurator - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/home/kidon/hibernate-3.1/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
2818 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
2819 [main] INFO org.hibernate.impl.SessionFactoryImpl - Checking 0 named queries
primary key is 20
2908 [main] INFO TestClient - updating honey
2931 [main] INFO TestClient - listing honey


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 5:25 pm 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:35 pm
Posts: 21
DAMN,

Logic seems far away, i just changed teh query to "from Honey", instead of "from honey", and it worked perfectly, but my table is defenitly called "honey" why the change in that letter ? Is it because of the mappings ?

Thx 4 UR time anyhow.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 5:30 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
just make sure you are using the cglib jar file that came with the hibernate3 download and make sure that you don't have any other versions of cglig on the classpath.

The log file excerpt you provided doesn't show any queries running or about to be run, maybe that's the problem.

also, set hibernate to show sql. and did you change that hql statement to just "from Honey" ?

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 5:33 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
kidon wrote:
DAMN,

Logic seems far away, i just changed teh query to "from Honey", instead of "from honey", and it worked perfectly, but my table is defenitly called "honey" why the change in that letter ? Is it because of the mappings ?

Thx 4 UR time anyhow.


Ha, I was typing the above response when you submitted yours.

yeah, HQL works off of class names. If you want to use sql you can use createSqlQuery

shoulda used the first recommendaiton i provided and the only one dennis provided first :)

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 6:19 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:35 pm
Posts: 21
OK, i'll check it.

Now comes the true question:

So I have a relational model, and i have the translation to the SQL tables. Should i just create mappings for the tables as they were translated from my relationel model, or should i give a large thought to my relational model, including cardinalties and stuff (as they are discribed in the manual), and then form my mappings ?

OK, not really making myself clear ...
So in short: Are the mappings dependent on my relational model or only on my resulting tables...



Thx


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 9:44 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
kidon wrote:
OK, i'll check it.

Now comes the true question:

So I have a relational model, and i have the translation to the SQL tables. Should i just create mappings for the tables as they were translated from my relationel model, or should i give a large thought to my relational model, including cardinalties and stuff (as they are discribed in the manual), and then form my mappings ?

OK, not really making myself clear ...
So in short: Are the mappings dependent on my relational model or only on my resulting tables...



Thx



Are you trying to make me think back to my CSA 385 database class?

The mappings are supposed to represent your relational model. They need to have programmed in them the relations as they should exist in your application. That way hibernate does all the db fetching and inserting work for you.

They should also mimic the databases functionality to help keep it in a functional state.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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