-->
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.  [ 7 posts ] 
Author Message
 Post subject: newbie stuck; can't get off first base
PostPosted: Wed Feb 23, 2005 10:40 pm 
Newbie

Joined: Wed Feb 23, 2005 9:57 pm
Posts: 16
I'm sure there must be some simple thing I've left out or have done incorrectly. My problem is that the generated sql has 0_ junk in it. I'm also not sure if the jndi warnings are part of the problem and if they need attention.

Thanks in advance for any help.

Hibernate version: hibernate-2.1.8

Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping package="waitlist">
<class name="waitlist.Facilities" table="facilities">
<id name="id" column="facil_id" type="long">
<generator class="native" />
</id>
<property name="fullName" />
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Session sess = sf.openSession();
Transaction tx = sess.beginTransaction();

qry = sess.createQuery("from Facilities");
tx.commit();

for (Iterator it = qry.iterate(); it.hasNext(); ) {
Facilities fac = (Facilities) it.next();
System.out.println(fac.toString());
}

sess.close();


Full stack trace of any exception that occurs:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
at javax.naming.InitialContext.getNameParser(InitialContext.java:439)
at net.sf.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
at net.sf.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:172)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:805)
at waitlist.Waitlist.main(Unknown Source)
Hibernate: select facilities0_.facil_id as x0_0_ from facilities facilities0_
WARN - SQL Error: 1054, SQLState: 42S22
ERROR - Unknown column 'facilities0_.facil_id' in 'field list'
WARN - SQL Error: 1054, SQLState: 42S22
ERROR - Unknown column 'facilities0_.facil_id' in 'field list'
Exception in thread "main" java.lang.RuntimeException: Could not execute query
at waitlist.Waitlist.main(Unknown Source)


Name and version of the database you are using:
mysql-4.1.8

The generated SQL (show_sql=true):
select facilities0_.facil_id as x0_0_ from facilities facilities0_

Debug level Hibernate log excerpt:
INFO - Hibernate 2.1.8
INFO - hibernate.properties not found
INFO - using CGLIB reflection optimizer
INFO - using JDK 1.4 java.sql.Timestamp handling
INFO - configuring from resource: /hibernate.cfg.xml
INFO - Configuration resource: /hibernate.cfg.xml
INFO - Mapping resource: Facilities.hbm.xml
INFO - Mapping class: waitlist.Facilities -> facilities
INFO - Configured SessionFactory: Waitlist
INFO - processing one-to-many association mappings
INFO - processing one-to-one association property references
INFO - processing foreign key constraints
INFO - Using dialect: net.sf.hibernate.dialect.MySQLDialect
INFO - Maximim outer join fetch depth: 2
INFO - Use outer join fetching: true
INFO - Using Hibernate built-in connection pool (not for production use!)
INFO - Hibernate connection pool size: 20
INFO - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/waitlist
INFO - connection properties: {user=user, password=secret}
INFO - Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactory
INFO - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
INFO - Use scrollable result sets: true
INFO - Use JDBC3 getGeneratedKeys(): true
INFO - Optimize cache for minimal puts: false
INFO - echoing all SQL to stdout
INFO - Query language substitutions: {}
INFO - cache provider: net.sf.hibernate.cache.HashtableCacheProvider
INFO - instantiating and configuring caches
INFO - building session factory
INFO - Factory name: Waitlist
INFO - JNDI InitialContext properties:{}
WARN - Could not bind factory to JNDI


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 5:34 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Looks like you have a probeme looking up/binding the SessionFactory into a JNDI namespace.

What sort of a context are you running this in (standalone or within a session bean?)

How are you retrieving your session factory?

Please show the hibernate.cfg.xml file (If you are using it)


BTW the 0_ junk junk are just automatically generated aliases for your tables/ columns


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 1:35 pm 
Newbie

Joined: Wed Feb 23, 2005 9:57 pm
Posts: 16
I'm running standalone. I was following the instructions by Michael Glögl, http://www.gloegl.de. Here is my hibernate.cfg.xml file

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory name="Waitlist">
<property name="show_sql">
true
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost/waitlist
</property>
<property name="hibernate.connection.username">
waitlist
</property>
<property name="hibernate.connection.password">
patience
</property>
<property name="dialect">
net.sf.hibernate.dialect.MySQLDialect
</property>
<property name="transaction.factory_class">
net.sf.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="hibernate.cache.provider_class">
net.sf.hibernate.cache.HashtableCacheProvider
</property>

<mapping resource="Facilities.hbm.xml"/>
</session-factory>
</hibernate-configuration>

The code for my sessionfactory is

Configuration cfg = new Configuration();
cfg.configure();
SessionFactory sf = cfg.buildSessionFactory();

Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 1:39 pm 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Remove
Quote:
name="Waitlist"

and try let me know what happens.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 2:27 pm 
Newbie

Joined: Wed Feb 23, 2005 9:57 pm
Posts: 16
That solves the jndi error/warning but it's still generating a mangled query with 0_ stuff in it:

INFO - Hibernate 2.1.8
INFO - hibernate.properties not found
INFO - using CGLIB reflection optimizer
INFO - using JDK 1.4 java.sql.Timestamp handling
INFO - configuring from resource: /hibernate.cfg.xml
INFO - Configuration resource: /hibernate.cfg.xml
INFO - Mapping resource: Facilities.hbm.xml
INFO - Mapping class: waitlist.Facilities -> facilities
INFO - Configured SessionFactory: null
INFO - processing one-to-many association mappings
INFO - processing one-to-one association property references
INFO - processing foreign key constraints
INFO - Using dialect: net.sf.hibernate.dialect.MySQLDialect
INFO - Maximim outer join fetch depth: 2
INFO - Use outer join fetching: true
INFO - Using Hibernate built-in connection pool (not for production use!)
INFO - Hibernate connection pool size: 20
INFO - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/waitlist
INFO - connection properties: {user=waitlist, password=patience}
INFO - Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactory
INFO - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
INFO - Use scrollable result sets: true
INFO - Use JDBC3 getGeneratedKeys(): true
INFO - Optimize cache for minimal puts: false
INFO - echoing all SQL to stdout
INFO - Query language substitutions: {}
INFO - cache provider: net.sf.hibernate.cache.HashtableCacheProvider
INFO - instantiating and configuring caches
INFO - building session factory
INFO - Not binding factory to JNDI, no JNDI name configured
Hibernate: select facilities0_.facil_id as x0_0_ from facilities facilities0_
WARN - SQL Error: 1054, SQLState: 42S22
ERROR - Unknown column 'facilities0_.facil_id' in 'field list'
WARN - SQL Error: 1054, SQLState: 42S22
ERROR - Unknown column 'facilities0_.facil_id' in 'field list'
Exception in thread "main" java.lang.RuntimeException: Could not execute query
at waitlist.Waitlist.main(Unknown Source)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 1:34 pm 
Newbie

Joined: Wed Feb 23, 2005 9:57 pm
Posts: 16
(Bump) I'm still hoping someone can help me with this; I'm completely stuck with this trivial sample application.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 1:47 pm 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
lumpynose wrote:
That solves the jndi error/warning but it's still generating a mangled query with 0_ stuff in it:
...
Hibernate: select facilities0_.facil_id as x0_0_ from facilities facilities0_
WARN - SQL Error: 1054, SQLState: 42S22
ERROR - Unknown column 'facilities0_.facil_id' in 'field list'

That "0_ stuff" is just standard SQL aliases. I don't think its the problem.

The error message "Unknown column 'facilities0_.facil_id' in 'field list'" strongly hints that there is no column called "facil_id" in the table "facilities". Is there such a column? You mapped it for the id property:

<id name="id" column="facil_id" type="long">

Also, what does a working SQL for this look like?


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