-->
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: cant get hibernate to work
PostPosted: Thu Jan 31, 2008 9:14 am 
Newbie

Joined: Sat Jan 26, 2008 7:26 am
Posts: 10
I have tried to get any hibernate tutorial to work but have failed every time. So today i tried a mysql+hibernate tutorial. It was possible to download everything. So i did and i just changed the hibernate.cfg.xml mysql user and password and created the database and tables. Still i can`t get the program to work. I must be doing something wrong. It can't be so ridiculously hard. This is what i get.

15:12:45,057 INFO Environment:464 - Hibernate 3.0.5
15:12:45,061 INFO Environment:477 - hibernate.properties not found
15:12:45,063 INFO Environment:510 - using CGLIB reflection optimizer
15:12:45,065 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling
15:12:45,131 INFO Configuration:1110 - configuring from resource: /hibernate.cfg.xml
15:12:45,132 INFO Configuration:1081 - Configuration resource: /hibernate.cfg.xml
15:12:45,280 INFO Configuration:444 - Mapping resource: de/laliluna/example/Honey.hbm.xml
15:12:45,407 INFO HbmBinder:260 - Mapping class: de.laliluna.example.Honey -> honey
15:12:45,419 INFO Configuration:1222 - Configured SessionFactory: null
15:12:45,421 DEBUG InitSessionFactory:113 - classic factory
15:12:45,422 INFO Configuration:875 - processing extends queue
15:12:45,422 INFO Configuration:879 - processing collection mappings
15:12:45,422 INFO Configuration:888 - processing association property references
15:12:45,422 INFO Configuration:917 - processing foreign key constraints
15:12:45,492 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
15:12:45,493 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
15:12:45,493 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
15:12:45,515 INFO DriverManagerConnectionProvider:80 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/firsthibernate
15:12:45,515 INFO DriverManagerConnectionProvider:86 - connection properties: {user=ivar, password=****}
15:12:45,838 WARN SettingsFactory:103 - Could not obtain connection metadata
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Last packet sent to the server was 1 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2104)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:729)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:154)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:72)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1004)
at de.laliluna.hibernate.InitSessionFactory.initSessionFactory(InitSessionFactory.java:114)
at de.laliluna.hibernate.InitSessionFactory.getInstance(InitSessionFactory.java:60)
at de.laliluna.example.TestExample.createHoney(TestExample.java:80)
at de.laliluna.example.TestExample.main(TestExample.java:33)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:209)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2027)
... 19 more
15:12:45,876 INFO Dialect:92 - Using dialect: org.hibernate.dialect.MySQLDialect
15:12:45,881 INFO TransactionFactoryFactory:34 - Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
15:12:45,883 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
15:12:45,884 INFO SettingsFactory:125 - Automatic flush during beforeCompletion(): disabled
15:12:45,884 INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled
15:12:45,887 INFO SettingsFactory:144 - Scrollable result sets: disabled
15:12:45,888 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): disabled
15:12:45,888 INFO SettingsFactory:160 - Connection release mode: null
15:12:45,889 INFO SettingsFactory:184 - Maximum outer join fetch depth: 2
15:12:45,889 INFO SettingsFactory:187 - Default batch fetch size: 1
15:12:45,889 INFO SettingsFactory:191 - Generate SQL with comments: disabled
15:12:45,890 INFO SettingsFactory:195 - Order SQL updates by primary key: disabled
15:12:45,890 INFO SettingsFactory:334 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
15:12:45,892 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory
15:12:45,892 INFO SettingsFactory:203 - Query language substitutions: {}
15:12:45,893 INFO SettingsFactory:209 - Second-level cache: enabled
15:12:45,893 INFO SettingsFactory:213 - Query cache: disabled
15:12:45,893 INFO SettingsFactory:321 - Cache provider: org.hibernate.cache.EhCacheProvider
15:12:45,895 INFO SettingsFactory:228 - Optimize cache for minimal puts: disabled
15:12:45,895 INFO SettingsFactory:237 - Structured second-level cache entries: disabled
15:12:45,960 INFO SettingsFactory:257 - Echoing all SQL to stdout
15:12:45,965 INFO SettingsFactory:261 - Statistics: disabled
15:12:45,965 INFO SettingsFactory:265 - Deleted entity synthetic identifier rollback: disabled
15:12:45,966 INFO SettingsFactory:279 - Default entity-mode: pojo
15:12:46,106 INFO SessionFactoryImpl:152 - building session factory
15:12:46,109 DEBUG CacheManager:191 - Creating new CacheManager with default config
15:12:46,112 DEBUG CacheManager:164 - Configuring ehcache from classpath.
15:12:46,114 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/home/ivar_m/workspace/FirstHibernateExample/lib/hibernate/ehcache-1.1.jar!/ehcache-failsafe.xml
15:12:46,120 DEBUG Configuration$DiskStore:185 - Disk Store Path: /tmp
15:12:46,394 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
15:12:46,395 INFO SessionFactoryImpl:379 - Checking 0 named queries
Exception in thread "main" org.hibernate.HibernateException: No TransactionManagerLookup specified
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:503)
at de.laliluna.example.TestExample.createHoney(TestExample.java:80)
at de.laliluna.example.TestExample.main(TestExample.java:33)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 10:05 am 
Newbie

Joined: Wed Jan 30, 2008 11:57 am
Posts: 3
hibernate.properties not found
i think this should be the main problem....
you have to check the path to your hiber.cfg.xml and that there aren't errors in itself!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 10:21 am 
Newbie

Joined: Sat Jan 26, 2008 7:26 am
Posts: 10
15:12:45,515 INFO DriverManagerConnectionProvider:86 - connection properties: {user=ivar, password=****}

But this line shows that it has taken information from hibernate.cfg.xml
Errors? I don`t know. I olny changed username and password.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost/firsthibernate</property>
<property name="connection.username">ivar</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.password">mypassword</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<!-- thread is the short name for
org.hibernate.context.ThreadLocalSessionContext
and let Hibernate bind the session automatically to the thread
-->
<property name="current_session_context_class">thread</property>
<!-- this will show us all sql statements -->
<property name="hibernate.show_sql">true</property>

<!-- mapping files -->
<mapping resource="de/laliluna/example/Honey.hbm.xml" />

</session-factory>
</hibernate-configuration>


Last edited by ivar_m on Thu Jan 31, 2008 10:24 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 10:22 am 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
Quote:
15:12:45,515 INFO DriverManagerConnectionProvider:80 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/firsthibernate
15:12:45,515 INFO DriverManagerConnectionProvider:86 - connection properties: {user=ivar, password=****}
15:12:45,838 WARN SettingsFactory:103 - Could not obtain connection metadata
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure


check that your mysql server is reachable under the address mentioned.
Is the database up and running?

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 10:32 am 
Newbie

Joined: Sat Jan 26, 2008 7:26 am
Posts: 10
mysql is running and i have created the database necessary. Im not sure how to check if it is reachable under the address mentioned. This worked:
mysql -u ivar -h localhost -p firsthibernate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 3:04 pm 
Newbie

Joined: Tue Nov 29, 2005 11:19 am
Posts: 3
just do what is written on : http://www.hibernate.org/152.html :

you should download the "Getting Started - Hello World" example from the book Java Persistence with Hibernate :

http://www.hibernate.org/hib_files/jpwh-gettingstarted-070401.zip

Just do what is in the readme, you just need ant,

It contains everything you need (ant launchers, jars, sources, an embedded hsql database and even a small visual sql tool ! ).


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.