- This topic has 24 replies, 2 voices, and was last updated 19 years, 3 months ago by
grb65a.
-
AuthorPosts
-
grb65aMemberI have been following the steps of the tutorial described in:
Hibernate Quickstart — MyEclipse Enterprise Workbench.pdfI have been using:
Eclipse 3.1
MyEclipse 4.0.0But rather than use MySQL, as the tutorial describes, I have been using HSQLDB.
So, there have been two things I have been doing differently:
1. The SQL described in the tutorial for creating the table is as follows:
CREATE TABLE echo_message
(
id INT(11) PRIMARY KEY not null,
msg VARCHAR(255)
)So I have had to use a different CREATE statement, as the above is not the correct syntax for HSQLDB. And I have probably gotten it wrong. What would be the equivalent statement in acceptable syntax for the HQSLDB database?
2. Also, I have been adding the Hsqldb.jar to my project and to my build path. This appears to be correct and necessary.
Below is my HibernateTest.java code – please also note that:
– I changed the import statement for hibernate to “org.” from “net.sf.” – the tutorial tells us to use Hibernate 3, but the code it provides for HibernateTest.java includes import statements for 2.1//HibernateTest.java
package com.genuitec.hibernate;
import org.hibernate.*;public class HibernateTest {
public static void main(String[] args) {
// Step 1 – Create a new entity
EchoMessage message = new EchoMessage();
// Step 2 – Set message field
message.setMsg(“hello”);
try {
// Step 3 – Get a Hibernate Session
Session session = SessionManager.currentSession();// Step 4 – Persist entity to database
Transaction tx = session.beginTransaction();
System.out.println(“Problem with next line?:”);
session.save(message);
System.out.println(“No Problem in previous line if you see this.”);
tx.commit();
System.out.println(“Save successful.”);
} catch (HibernateException e) {
System.out.println(e.getMessage());
System.out.println(“Save failed.”);
} finally {
try {
// Step 5 – close the session
SessionManager.closeSession();
} catch (HibernateException e1) {
// do nothing
}
}
}
}And below, are the results of running the above:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Problem with next line?:
could not fetch initial value
Save failed.I recognize that the log4j warnings are fine. But why am I getting:
could not fetch initial value
Save failed.If useful for understanding this, below is the code of the other project files which were generated by the tutorial:
//AbstractEchoMessage.java:
/*
* WARNING: DO NOT EDIT THIS FILE. This is a generated file that is synchronized
* by MyEclipse Hibernate tool integration.
*
* Created Fri Jan 20 19:57:08 EST 2006 by MyEclipse Hibernate Tool.
*/
package com.genuitec.hibernate;import java.io.Serializable;
/**
* A class that represents a row in the ECHO_MESSAGE table.
* You can customize the behavior of this class by editing the class, {@link EchoMessage()}.
* WARNING: DO NOT EDIT THIS FILE. This is a generated file that is synchronized
* by MyEclipse Hibernate tool integration.
*/
public abstract class AbstractEchoMessage
implements Serializable
{
/** The cached hash code value for this instance. Settting to 0 triggers re-calculation. */
private int hashValue = 0;/** The composite primary key value. */
private java.lang.Integer id;/** The value of the simple msg property. */
private java.lang.String msg;/**
* Simple constructor of AbstractEchoMessage instances.
*/
public AbstractEchoMessage()
{
}/**
* Constructor of AbstractEchoMessage instances given a simple primary key.
* @param id
*/
public AbstractEchoMessage(java.lang.Integer id)
{
this.setId(id);
}/**
* Return the simple primary key value that identifies this object.
* @return java.lang.Integer
*/
public java.lang.Integer getId()
{
return id;
}/**
* Set the simple primary key value that identifies this object.
* @param id
*/
public void setId(java.lang.Integer id)
{
this.hashValue = 0;
this.id = id;
}/**
* Return the value of the MSG column.
* @return java.lang.String
*/
public java.lang.String getMsg()
{
return this.msg;
}/**
* Set the value of the MSG column.
* @param msg
*/
public void setMsg(java.lang.String msg)
{
this.msg = msg;
}/**
* Implementation of the equals comparison on the basis of equality of the primary key values.
* @param rhs
* @return boolean
*/
public boolean equals(Object rhs)
{
if (rhs == null)
return false;
if (! (rhs instanceof EchoMessage))
return false;
EchoMessage that = (EchoMessage) rhs;
if (this.getId() == null || that.getId() == null)
return false;
return (this.getId().equals(that.getId()));
}/**
* Implementation of the hashCode method conforming to the Bloch pattern with
* the exception of array properties (these are very unlikely primary key types).
* @return int
*/
public int hashCode()
{
if (this.hashValue == 0)
{
int result = 17;
int idValue = this.getId() == null ? 0 : this.getId().hashCode();
result = result * 37 + idValue;
this.hashValue = result;
}
return this.hashValue;
}
}————————————————————————————-
//EchoMessage.java
/*
* Created Fri Jan 20 19:57:08 EST 2006 by MyEclipse Hibernate Tool.
*/
package com.genuitec.hibernate;import java.io.Serializable;
/**
* A class that represents a row in the ‘ECHO_MESSAGE’ table.
* This class may be customized as it is never re-generated
* after being created.
*/
public class EchoMessage
extends AbstractEchoMessage
implements Serializable
{
/**
* Simple constructor of EchoMessage instances.
*/
public EchoMessage()
{
}/**
* Constructor of EchoMessage instances given a simple primary key.
* @param id
*/
public EchoMessage(java.lang.Integer id)
{
super(id);
}/* Add customized code below */
}
—————————————————————————
//SessionManager.java:
package com.genuitec.hibernate;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;/**
* Configures and provides access to Hibernate sessions, tied to the
* current thread of execution. Follows the Thread Local Session
* pattern, see {@link http://hibernate.org/42.html}.
*/
public class SessionManager {/**
* Location of hibernate.cfg.xml file.
* NOTICE: Location should be on the classpath as Hibernate uses
* #resourceAsStream style lookup for its configuration file. That
* is place the config file in a Java package – the default location
* is the default Java package.<br><br>
* Examples: <br>
* <code>CONFIG_FILE_LOCATION = “/hibernate.conf.xml”.
* CONFIG_FILE_LOCATION = “/com/foo/bar/myhiberstuff.conf.xml”.</code>
*/
private static String CONFIG_FILE_LOCATION = “/hibernate.cfg.xml”;/** Holds a single instance of Session */
private static final ThreadLocal threadLocal = new ThreadLocal();/** The single instance of hibernate configuration */
private static final Configuration cfg = new Configuration();/** The single instance of hibernate SessionFactory */
private static org.hibernate.SessionFactory sessionFactory;/**
* Returns the ThreadLocal Session instance. Lazy initialize
* the <code>SessionFactory</code> if needed.
*
* @return Session
* @throws HibernateException
*/
public static Session currentSession() throws HibernateException {
Session session = (Session) threadLocal.get();if (session == null) {
if (sessionFactory == null) {
try {
cfg.configure(CONFIG_FILE_LOCATION);
sessionFactory = cfg.buildSessionFactory();
}
catch (Exception e) {
System.err.println(“%%%% Error Creating SessionFactory %%%%”);
e.printStackTrace();
}
}
session = sessionFactory.openSession();
threadLocal.set(session);
}return session;
}/**
* Close the single hibernate session instance.
*
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);if (session != null) {
session.close();
}
}/**
* Default constructor.
*/
private SessionManager() {
}}
———————————————————————————————-
//EchoMessage.hbm.xml:
<?xml version=”1.0″ encoding=’UTF-8′?>
<!DOCTYPE hibernate-mapping PUBLIC
“-//Hibernate/Hibernate Mapping DTD 3.0//EN”
“http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd” ><!– DO NOT EDIT: This is a generated file that is synchronized –>
<!– by MyEclipse Hibernate tool integration. –>
<!– Created Fri Jan 20 19:57:08 EST 2006 –>
<hibernate-mapping package=”com.genuitec.hibernate”><class name=”EchoMessage” table=”ECHO_MESSAGE”>
<id name=”id” column=”ID” type=”integer”>
<generator class=”increment”/>
</id><property name=”msg” column=”MSG” type=”string” />
</class></hibernate-mapping>
Thanks in advance for any help…
Riyad KallaMemberI have no idea why you are getting that. If you turn the logging off, do you still see it? It’s strange there is no indicator where it is comming from or what log level it was logged at. Makes me think that it’s from your code somewhere.
grb65aMemberThank you for your quick response. Okay, so just to show off my ignorance, um, how do I turn off logging? Though again, I don’t think the log4j error message is the problem. I believe this tutorial (or others I have read), suggest that it is okay to ignore logging related errors (???), but just to eliminate a potential variable, I will be glad to disable logging.
But to be clear, what I am asking is why the following line is not executing:
session.save(message);
And why I am getting the following error message in result:
could not fetch initial value
Save failed.I don’t think these error messages relate to the log4j error message that precedes them – particularly as I have added a bit of debugging code that results in printing a line to the console in between the log4j errors and the error messages in question. If you look again at my code, it seems to me that the following segment:
System.out.println(“Problem with next line?:”);
session.save(message);
System.out.println(“No Problem in previous line if you see this.”);
tx.commit();
System.out.println(“Save successful.”);
} catch (HibernateException e) {
System.out.println(e.getMessage());
System.out.println(“Save failed.”);is resulting in:
Problem with next line?:
could not fetch initial value
Save failed.And the log3j error messages that precede this are not related.
I’m new to submitting questions to a forum like this, so don’t know what is or isn’t a reasonable request, but do you have the ability to try to execute the steps of the tutorial using hsqldb? Or even just using mySQL as the tutorial specifies to confirm it is correct without modifications to begin with?
Thanks again…
Riyad KallaMemberThank you for your quick response. Okay, so just to show off my ignorance, um, how do I turn off logging?
My mistake, I thought you had configured Log4j, I see you hadn’t. Nothing to change here.
session.save(message);
And why I am getting the following error message in result:
could not fetch initial value
Save failed.Ahh, thank you for clarifying. In that nightmare of a post above it was hard to tell where your questions were (tip: http://www.myeclipseide.com/PNphpBB2+file-viewtopic-t-6922.html)
I would suggest editing your hibernate.cfg.xml file and setting show_sql to true, so you can see what Hibernate is trying to execute. You may have an invalid type for the message class somewhere. Also be sure you are using the most recently hsql version, we have seen a lot of “weird errors” disappear with the database explorer when folks upgraded, so I think they fixed some bugs.
grb65aMemberThanks, okay, four questions:
1. I think I can safely say that there is not a problem with how I am using hsqldb.jar, but can you tell me if I am not thinking of something?:
– I have been using HSQLDB1.8.0.1, which I believe is the latest release.
– I am using the same copy of it everywhere: When I import hsqldb.jar to my project and add it to my buildpath (which I do even though the tutorial does not say to import or add it), I add it from the same directory on my file system which I specify in my Database Connection (from Window/Preferences, then having selected HSQLDB Standalone and then Edit, the path is defined under Driver libraries)
– The database can be communicated with using the MyEclipse Database Manager, and its SQL Editor – with these tools, I can CREATE tables, INSERT or SELECT successfully.2. Could it be that I should be adding other resources to get this to work besides hsqldb.jar? Are there other items I should be importing manually or adding to the build path? Perhaps some other files associated with hsqldb.jar?
3. Like you suggested, I added the following to hibernate.cfg.xml:
<property name=”show_sql”>true</property>
But this didn’t cause anything different to occur. What should have this shown me?4. In EchoMessage.java, I am also now noticing a warning:
“The serializable class EchoMessage does not declare a static final SerialVersionUID field of type long.”
What should I do to fix this? Could this be the issue?Thanks again…
Riyad KallaMember1. I think I can safely say that there is not a problem with how I am using hsqldb.jar, but can you tell me if I am not thinking of something?:
No
2. Could it be that I should be adding other resources to get this to work besides hsqldb.jar? Are there other items I should be importing manually or adding to the build path? Perhaps some other files associated with hsqldb.jar?
Not that I’m aware of.
3. Like you suggested, I added the following to hibernate.cfg.xml:
<property name=”show_sql”>true</property>
But this didn’t cause anything different to occur. What should have this shown me?It should have shown you the SQL it generated to execute the save.
4. In EchoMessage.java, I am also now noticing a warning:
“The serializable class EchoMessage does not declare a static final SerialVersionUID field of type long.”
What should I do to fix this? Could this be the issue?This is an Eclipse warning new with 3.1, your class implements Serializable but does not provide a unique ID. THat’s generally not good practice but you can ignore it for now.
What I would like you to do is paste your hibernate.cfg.xml file in here for me to look at.
grb65aMemberThank you. Below are the contents of hibernate.cfg.xml – I should have provided this originally:
<?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”><!– Generated by MyEclipse Hibernate Tools. –>
<hibernate-configuration><session-factory>
<property name=”myeclipse.connection.profile”>
HSQLDB Connection 04 – dbtest
</property>
<property name=”connection.url”>jdbc:hsqldb:dbtest</property>
<property name=”connection.username”>sa</property>
<property name=”connection.password”></property>
<property name=”connection.driver_class”>
org.hsqldb.jdbcDriver
</property>
<property name=”dialect”>
org.hibernate.dialect.HSQLDialect
</property><mapping resource=”com/genuitec/hibernate/EchoMessage.hbm.xml” /></session-factory>
</hibernate-configuration>
Riyad KallaMemberUnforunately it’s hard for me to say why Hibernate is barfing on you. The next step would be to turn on logging for hibernate, you can learn about that here:
http://www.hibernate.org/hib_docs/v3/reference/en/html/session-configuration.html#configuration-loggingAnd learn how to setup a log4j.properties file here:
http://logging.apache.org/log4j/docs/manual.html
grb65aMemberOkay,… Great, thank you, … so what I did this morning was as follows:
1. From scratch, I reconstructed my project, and I wrote out what I did step-by-step. What results is below, and if corrected, could become a variation on your provided tutorial, for using MyEclispe to connect a Project to HSQLDB, rather than Oracle or MySQL.
2. I executed it and saw the exact same results I have been seeing, then added logging as you suggested and saw the results of this…So I am thinking that either:
a. You will be able to look at the very bottom of this post, and see the results of logging being enabled, and from that see what I am doing wrong.
b. Or you might be willing to read through or reproduce the steps of the tutorial I have written immediately below, and determine where I have an incorrect step or a missing step.(SLIGHTLY BROKEN) TUTORIAL FOR EMPLOYING HIBERNATE TO CONNECT A JAVA PROJECT TO HSQLDB1.8.0.1, USING ECLIPSE 3.1 WITH MYECLIPSE 4.0.0
2006 01 26 The following describes the exact sequence of steps I have completed this morning to employ Hibernate to connect a Java Project to HSQLDB1.8.0.1, using Eclipse 3.1 with MyEclipse 4.0.0. This sequence of steps is based on the instructions provided by MyEclipse Hibernate Quickstart, Last Revision: January 26, 2006 , accessible from:
http://myeclipseide.com/enterpriseworkbench/help/index.jsp?topic=/com.genuitec.myeclipse.doc/html/quickstarts/hibernate/index.html.Please note that it does include various steps not made explicit in that tutorial.
1. Downloaded hsqldb_1_8_0_1.zip to my computer.
2. Extracted it to create HSQLDB1.8.0.1 resources in c:\hsqldb\
3. Opened Eclipse 3.1 with MyEclipse 4.0.0 already installed.
4. Clicked Window/OpenPerspective/Other/MyEclipse Database Explorer5. Clicked Window/Preferences/MyEclipse/Database Explorer/Drivers and Selected HSQLDB Standalone and then Edit.
Name: HSQLDB Standalone
Example URL: jdbc:hsqldb:hello
Java Class Path: C:\Eclipse\startup.jar
Driver libraries: C:hsqldb\lib\hsqldb.jar
Driver class name: org.hsqldb.jdbcDriverClicked OK, Apply, OK.
6. Clicked on Database Explorer New Connection Icon and created:
Profile Name: HSQLDB Connection 20
Show Drivers: All
Driver: HSQLDB Standalone
URL: jdbc:hsqldb:hello
UserName: sa
Password: <blank>
Open On Eclipse Startup: <Unchecked>
Prompt for Password: checkedClicked Next:
Selected Display all Schemas
Clicked Finish.
7. With the Connection Profile just created selected, clicked on Open Connection Icon. With Autocommit checked, clicked OK in response to LogIn dialog.
8. Clicked on “+” next to Connection and selected:Connected to HSQLDB Connection 20
9. Clicked DB Connection Info.
HSQL Database Engine
Database Product Version: 1.8.0
Driver Major: Version 1
Driver Minor: Version 8
Driver Name: HSQL Database Driver
Driver Version: 1.8.0
User Name: SA
URL: jdbc:hsqldb:hello
Autocommit Mode: True
… many other details…10. Right Clicked on Connected to HSQLDB Connection 20
Selected New SQL Editor
11. Entered the following into the New SQL Editor and clicked ‘Running Man’ Icon:
CREATE TABLE MyTable(id INT primary key, stuff varchar(255));
It ran, no error message resulted.
12. Expanded HSQLDB Connection 20 in the DB Browser. Found PUBLIC/TABLE and selected TABLE. RIght clicked and clicked Refresh. Then found the newly created MYTABLE with the columns ID and STUFF. Saw that ID is shown with a key over or part of its column icon.
13. Closed the SQL Editor.
14. Clicked Window/OpenPerspective/Other/Java(default).
15. Clicked File/New/Project.
Selected Java Project and clicked Next.
Project Name: HibernateDemo20
Create New Project in Workspace
Use Default Compiler
Checked Create Separate Source and Output Folders
Clicked NextSaw in the next Dialog:
Default Output Folder: HibernateDemo20/bin
Clicked Finish16. With the Project HibernateDemo20 selected, Clicked MyEclipse/Add Hibernate Capabilities.
Hibernate Specification: Hibernate 3
Library Folder: /lib
Checked: Append Hibernate libraries to project classpath
Hibernate Config File: NewClicked Next
Configuration Folder Path: /HibernateDemo20/src
Configuration File Name: hibernate.cfg.xmlClicked Next
Checked: Create SessionFactory Class
Session Factory Class: com.genuitec.hibernate.SessionManager
Source Folder: /srcClicked Finish
17. In hibernate.cfg.xml, configured database connection profile:
Selected: Use JDBC Driver
DB Connect Profile: HSQLDB Connection 20
URL: jdbc:hsqldb:hello
Driver: org.hsqldb.jdbcDriver
User Name: SA
Password: <blank>
Dialect: HypersonicSQL
Did not click Copy JDBC Driver and Add to Classpath
Saved file.
Closed file.18. Clicked Window/OpenPerspective/Other/MyEclipse Database Explorer
19. Selected MYTABLE, right clicked and clicked Create Hibernate Mapping.Location: /HibernateDemo20/src/com/genuitec/hibernate
Base Persistence Class: <blank>
ID Generator: Increment
Types: Use Hibernate Types
Checked: Update Hibernate Configuration File.Clicked Finish.
20. Confirmed in Project HibernateDemo20, existence under src/com/genuitec/hibernate:
AbstractMyTable.java
MyTable.java
MyTable.hbm.xml
SessionManager.java21. In /src/com.genuitec.hibernate, created a Java Class HibernateTest by selecting File/New/Class then:
Source Folder: HibernateDemo20/src
Package: com.genuitec.hibernate
Name: HibernateTest
Superclass: java.lang.Object
Checked public static void main(String[]args)
Checked Inherited abstract methods
Finish22. Copied the following to be the entire contents of HibernateTest:
package com.genuitec.hibernate;
import org.hibernate.*;
//import org.hsqldb.SessionInterface;
public class HibernateTest {
public static void main(String[] args) {
// Step 1 – Create a new entity
Mytable sss = new Mytable();
// Step 2 – Set message field
sss.setStuff(“hello”);try {
// Step 3 – Get a Hibernate Session
Session session = SessionManager.currentSession();// Step 4 – Persist entity to database
Transaction tx = session.beginTransaction();System.out.println(“Problem with next line?:”);
session.save(sss);
System.out.println(“No Problem in previous line if you see this.”);
tx.commit();
System.out.println(“Save successful.”);
} catch (HibernateException e) {
System.out.println(e.getMessage());
System.out.println(“Save failed.”);
} finally {
try {
// Step 5 – close the session
SessionManager.closeSession();
} catch (HibernateException e1) {
// do nothing
}
}
}
}23. In the Package Explorer, selected HibernateDemo20, and then imported the following (with Create selected folders only checked):
C: \hsqldb\lib\hsqldb.jar
The found it in the Package Explorer, right clicked it, selected Build Path, and clicked Add it to the build path. In result, saw that its icon changed from a document to a jar.
24. Selected HibernateTest and clicked Run/Run as Java Application.
Saw the following in the console in result:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Problem with next line?:
could not fetch initial value
Save failed.25. So,… opened hibernate.cfg.xml. Added a property of
max_fetch_depth
1Saved it. Then, looked at the source for this file and saw the following:
<?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”><!– Generated by MyEclipse Hibernate Tools. –>
<hibernate-configuration><session-factory>
<property name=”myeclipse.connection.profile”>
HSQLDB Connection 20
</property>
<property name=”connection.url”>jdbc:hsqldb:hello</property>
<property name=”connection.username”>sa</property>
<property name=”connection.password”></property>
<property name=”connection.driver_class”>
org.hsqldb.jdbcDriver
</property>
<property name=”dialect”>
org.hibernate.dialect.HSQLDialect
</property>
<property name=”max_fetch_depth”>1</property>
<mapping resource=”com/genuitec/hibernate/Mytable.hbm.xml”></mapping></session-factory>
</hibernate-configuration>
26. Again selected HibernateTest and clicked Run/Run as Java Application. Saw the same result:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Problem with next line?:
could not fetch initial value
Save failed.27. So… in the Package Explorer, selected HibernateDemo20, and then imported the following (with Create selected folders only checked):
C: \ hibernate-3.1\etc\log4j.properties
Saw in the Package Explorer that in the Project log4j-1.2.9.jar was now shown with a jar icon and log4j.properties was shown with a document icon.
Copied and pasted log4j.properties to under /src/ and then deleted it from where it was prior.
28. Again selected HibernateTest and clicked Run/Run as Java Application. Saw the following result:
10:01:05,890 INFO Environment:464 – Hibernate 3.0.5
10:01:05,921 INFO Environment:477 – hibernate.properties not found
10:01:05,968 INFO Environment:510 – using CGLIB reflection optimizer
10:01:05,968 INFO Environment:540 – using JDK 1.4 java.sql.Timestamp handling
10:01:06,218 INFO Configuration:1110 – configuring from resource: /hibernate.cfg.xml
10:01:06,218 INFO Configuration:1081 – Configuration resource: /hibernate.cfg.xml
10:01:07,343 INFO Configuration:444 – Mapping resource: com/genuitec/hibernate/Mytable.hbm.xml
10:01:08,078 INFO HbmBinder:260 – Mapping class: com.genuitec.hibernate.Mytable -> MYTABLE
10:01:08,140 INFO Configuration:1222 – Configured SessionFactory: null
10:01:08,140 INFO Configuration:875 – processing extends queue
10:01:08,140 INFO Configuration:879 – processing collection mappings
10:01:08,140 INFO Configuration:888 – processing association property references
10:01:08,140 INFO Configuration:917 – processing foreign key constraints
10:01:08,343 INFO DriverManagerConnectionProvider:41 – Using Hibernate built-in connection pool (not for production use!)
10:01:08,343 INFO DriverManagerConnectionProvider:42 – Hibernate connection pool size: 20
10:01:08,343 INFO DriverManagerConnectionProvider:45 – autocommit mode: false
10:01:08,421 INFO DriverManagerConnectionProvider:80 – using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hello
10:01:08,421 INFO DriverManagerConnectionProvider:86 – connection properties: {user=sa, password=****}
10:01:09,359 INFO SettingsFactory:77 – RDBMS: HSQL Database Engine, version: 1.8.0
10:01:09,359 INFO SettingsFactory:78 – JDBC driver: HSQL Database Engine Driver, version: 1.8.0
10:01:09,484 INFO Dialect:92 – Using dialect: org.hibernate.dialect.HSQLDialect
10:01:09,484 INFO TransactionFactoryFactory:31 – Using default transaction strategy (direct JDBC transactions)
10:01:09,484 INFO TransactionManagerLookupFactory:33 – No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
10:01:09,484 INFO SettingsFactory:125 – Automatic flush during beforeCompletion(): disabled
10:01:09,484 INFO SettingsFactory:129 – Automatic session close at end of transaction: disabled
10:01:09,484 INFO SettingsFactory:136 – JDBC batch size: 15
10:01:09,500 INFO SettingsFactory:139 – JDBC batch updates for versioned data: disabled
10:01:09,515 INFO SettingsFactory:144 – Scrollable result sets: enabled
10:01:09,515 INFO SettingsFactory:152 – JDBC3 getGeneratedKeys(): disabled
10:01:09,515 INFO SettingsFactory:160 – Connection release mode: null
10:01:09,515 INFO SettingsFactory:184 – Maximum outer join fetch depth: 1
10:01:09,515 INFO SettingsFactory:187 – Default batch fetch size: 1
10:01:09,515 INFO SettingsFactory:191 – Generate SQL with comments: disabled
10:01:09,515 INFO SettingsFactory:195 – Order SQL updates by primary key: disabled
10:01:09,515 INFO SettingsFactory:334 – Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
10:01:09,531 INFO ASTQueryTranslatorFactory:21 – Using ASTQueryTranslatorFactory
10:01:09,531 INFO SettingsFactory:203 – Query language substitutions: {}
10:01:09,531 INFO SettingsFactory:209 – Second-level cache: enabled
10:01:09,531 INFO SettingsFactory:213 – Query cache: disabled
10:01:09,531 INFO SettingsFactory:321 – Cache provider: org.hibernate.cache.EhCacheProvider
10:01:09,593 INFO SettingsFactory:228 – Optimize cache for minimal puts: disabled
10:01:09,593 INFO SettingsFactory:237 – Structured second-level cache entries: disabled
10:01:09,609 INFO SettingsFactory:261 – Statistics: disabled
10:01:09,609 INFO SettingsFactory:265 – Deleted entity synthetic identifier rollback: disabled
10:01:09,625 INFO SettingsFactory:279 – Default entity-mode: pojo
10:01:10,187 INFO SessionFactoryImpl:152 – building session factory
10:01:10,234 WARN Configurator:126 – No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/Owner/My%20Documents/Workspace/HibernateDemo20/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
10:01:10,875 INFO SessionFactoryObjectFactory:82 – Not binding factory to JNDI, no JNDI name configured
10:01:10,875 INFO SessionFactoryImpl:379 – Checking 0 named queries
Problem with next line?:
10:01:10,953 WARN JDBCExceptionReporter:71 – SQL Error: -22, SQLState: S0002
10:01:10,968 ERROR JDBCExceptionReporter:72 – Table not found in statement [select max(ID) from MYTABLE]
could not fetch initial value
Save failed.… Where to go from here???
Riyad KallaMemberInteresting, can you paste what was generated for MyTable.hbm.xml?
I wonder if this could be a case sensativity issue. Also be sure to turn show_sql to true in your hiberante.cfg.xml file so we can see it.
grb65aMemberThank you very much again. Okay, I did two things in response to your suggestions. First, here is the contents of Mytable.hbm.xml as you requested:
<?xml version="1.0" encoding='UTF-8'?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <!-- DO NOT EDIT: This is a generated file that is synchronized --> <!-- by MyEclipse Hibernate tool integration. --> <!-- Created Thu Jan 26 09:21:27 EST 2006 --> <hibernate-mapping package="com.genuitec.hibernate"> <class name="Mytable" table="MYTABLE"> <id name="id" column="ID" type="integer"> <generator class="increment"/> </id> <property name="stuff" column="STUFF" type="string" /> </class> </hibernate-mapping>
Second, I added show_sql=true to hibernate.cfg.xml so that its source became as follow:
<?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"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <property name="myeclipse.connection.profile"> HSQLDB Connection 20 </property> <property name="connection.url">jdbc:hsqldb:hello</property> <property name="connection.username">sa</property> <property name="connection.password"></property> <property name="connection.driver_class"> org.hsqldb.jdbcDriver </property> <property name="dialect"> org.hibernate.dialect.HSQLDialect </property> <property name="max_fetch_depth">1</property> <property name="show_sql">true</property> <mapping resource="com/genuitec/hibernate/Mytable.hbm.xml"></mapping> </session-factory> </hibernate-configuration>
… Then, I ran HibernateTest.java again and saw:
15:33:53,046 INFO Environment:464 - Hibernate 3.0.5 15:33:53,093 INFO Environment:477 - hibernate.properties not found 15:33:53,140 INFO Environment:510 - using CGLIB reflection optimizer 15:33:53,140 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling 15:33:53,515 INFO Configuration:1110 - configuring from resource: /hibernate.cfg.xml 15:33:53,515 INFO Configuration:1081 - Configuration resource: /hibernate.cfg.xml 15:33:54,859 INFO Configuration:444 - Mapping resource: com/genuitec/hibernate/Mytable.hbm.xml 15:33:55,640 INFO HbmBinder:260 - Mapping class: com.genuitec.hibernate.Mytable -> MYTABLE 15:33:55,734 INFO Configuration:1222 - Configured SessionFactory: null 15:33:55,734 INFO Configuration:875 - processing extends queue 15:33:55,734 INFO Configuration:879 - processing collection mappings 15:33:55,734 INFO Configuration:888 - processing association property references 15:33:55,734 INFO Configuration:917 - processing foreign key constraints 15:33:56,390 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!) 15:33:56,390 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20 15:33:56,406 INFO DriverManagerConnectionProvider:45 - autocommit mode: false 15:33:56,453 INFO DriverManagerConnectionProvider:80 - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hello 15:33:56,453 INFO DriverManagerConnectionProvider:86 - connection properties: {user=sa, password=****} 15:33:58,671 INFO SettingsFactory:77 - RDBMS: HSQL Database Engine, version: 1.8.0 15:33:58,671 INFO SettingsFactory:78 - JDBC driver: HSQL Database Engine Driver, version: 1.8.0 15:33:59,125 INFO Dialect:92 - Using dialect: org.hibernate.dialect.HSQLDialect 15:33:59,125 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions) 15:33:59,125 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended) 15:33:59,125 INFO SettingsFactory:125 - Automatic flush during beforeCompletion(): disabled 15:33:59,125 INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled 15:33:59,125 INFO SettingsFactory:136 - JDBC batch size: 15 15:33:59,125 INFO SettingsFactory:139 - JDBC batch updates for versioned data: disabled 15:33:59,140 INFO SettingsFactory:144 - Scrollable result sets: enabled 15:33:59,140 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): disabled 15:33:59,140 INFO SettingsFactory:160 - Connection release mode: null 15:33:59,140 INFO SettingsFactory:184 - Maximum outer join fetch depth: 1 15:33:59,140 INFO SettingsFactory:187 - Default batch fetch size: 1 15:33:59,140 INFO SettingsFactory:191 - Generate SQL with comments: disabled 15:33:59,140 INFO SettingsFactory:195 - Order SQL updates by primary key: disabled 15:33:59,140 INFO SettingsFactory:334 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory 15:33:59,171 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory 15:33:59,171 INFO SettingsFactory:203 - Query language substitutions: {} 15:33:59,171 INFO SettingsFactory:209 - Second-level cache: enabled 15:33:59,171 INFO SettingsFactory:213 - Query cache: disabled 15:33:59,171 INFO SettingsFactory:321 - Cache provider: org.hibernate.cache.EhCacheProvider 15:33:59,250 INFO SettingsFactory:228 - Optimize cache for minimal puts: disabled 15:33:59,265 INFO SettingsFactory:237 - Structured second-level cache entries: disabled 15:33:59,281 INFO SettingsFactory:257 - Echoing all SQL to stdout 15:33:59,281 INFO SettingsFactory:261 - Statistics: disabled 15:33:59,281 INFO SettingsFactory:265 - Deleted entity synthetic identifier rollback: disabled 15:33:59,281 INFO SettingsFactory:279 - Default entity-mode: pojo 15:33:59,953 INFO SessionFactoryImpl:152 - building session factory 15:34:00,015 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/Owner/My%20Documents/Workspace/HibernateDemo20/lib/ehcache-1.1.jar!/ehcache-failsafe.xml 15:34:00,531 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured 15:34:00,531 INFO SessionFactoryImpl:379 - Checking 0 named queries Problem with next line?: 15:34:00,765 WARN JDBCExceptionReporter:71 - SQL Error: -22, SQLState: S0002 15:34:00,765 ERROR JDBCExceptionReporter:72 - Table not found in statement [select max(ID) from MYTABLE] could not fetch initial value Save failed.
I hope this is useful…
Riyad KallaMemberChange the mapping file to match the exact case of your table as you see int the DB Explorer (e.g. MyTable) right now it is MYTABLE.
grb65aMemberIn the DB Browser, it shows MYTABLE, all in caps, as follows:
HSQLDB Connection 20
– Connected to HSQLDB Connection 20
— PUBLIC
— TABLE
—- MYTABLEBut thinking your suggestion made sense, and just to try different possibilities, first I tried “MyTable”, changing the contents of Mytable.hbm.xml to:
<?xml version="1.0" encoding='UTF-8'?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <!-- DO NOT EDIT: This is a generated file that is synchronized --> <!-- by MyEclipse Hibernate tool integration. --> <!-- Created Thu Jan 26 09:21:27 EST 2006 --> <hibernate-mapping package="com.genuitec.hibernate"> <class name="Mytable" table="MyTable"> <id name="id" column="ID" type="integer"> <generator class="increment"/> </id> <property name="stuff" column="STUFF" type="string" /> </class> </hibernate-mapping>
Then I ran HibernateTest.java again and saw:
16:27:04,625 INFO Environment:464 - Hibernate 3.0.5 16:27:04,656 INFO Environment:477 - hibernate.properties not found 16:27:04,656 INFO Environment:510 - using CGLIB reflection optimizer 16:27:04,656 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling 16:27:04,734 INFO Configuration:1110 - configuring from resource: /hibernate.cfg.xml 16:27:04,734 INFO Configuration:1081 - Configuration resource: /hibernate.cfg.xml 16:27:05,171 INFO Configuration:444 - Mapping resource: com/genuitec/hibernate/Mytable.hbm.xml 16:27:05,328 INFO HbmBinder:260 - Mapping class: com.genuitec.hibernate.Mytable -> MyTable 16:27:05,390 INFO Configuration:1222 - Configured SessionFactory: null 16:27:05,390 INFO Configuration:875 - processing extends queue 16:27:05,390 INFO Configuration:879 - processing collection mappings 16:27:05,390 INFO Configuration:888 - processing association property references 16:27:05,390 INFO Configuration:917 - processing foreign key constraints 16:27:05,468 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!) 16:27:05,468 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20 16:27:05,468 INFO DriverManagerConnectionProvider:45 - autocommit mode: false 16:27:05,484 INFO DriverManagerConnectionProvider:80 - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hello 16:27:05,484 INFO DriverManagerConnectionProvider:86 - connection properties: {user=sa, password=****} 16:27:06,359 INFO SettingsFactory:77 - RDBMS: HSQL Database Engine, version: 1.8.0 16:27:06,359 INFO SettingsFactory:78 - JDBC driver: HSQL Database Engine Driver, version: 1.8.0 16:27:06,515 INFO Dialect:92 - Using dialect: org.hibernate.dialect.HSQLDialect 16:27:06,531 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions) 16:27:06,531 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended) 16:27:06,531 INFO SettingsFactory:125 - Automatic flush during beforeCompletion(): disabled 16:27:06,531 INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled 16:27:06,531 INFO SettingsFactory:136 - JDBC batch size: 15 16:27:06,531 INFO SettingsFactory:139 - JDBC batch updates for versioned data: disabled 16:27:06,531 INFO SettingsFactory:144 - Scrollable result sets: enabled 16:27:06,531 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): disabled 16:27:06,531 INFO SettingsFactory:160 - Connection release mode: null 16:27:06,531 INFO SettingsFactory:184 - Maximum outer join fetch depth: 1 16:27:06,531 INFO SettingsFactory:187 - Default batch fetch size: 1 16:27:06,531 INFO SettingsFactory:191 - Generate SQL with comments: disabled 16:27:06,531 INFO SettingsFactory:195 - Order SQL updates by primary key: disabled 16:27:06,531 INFO SettingsFactory:334 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory 16:27:06,593 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory 16:27:06,593 INFO SettingsFactory:203 - Query language substitutions: {} 16:27:06,593 INFO SettingsFactory:209 - Second-level cache: enabled 16:27:06,593 INFO SettingsFactory:213 - Query cache: disabled 16:27:06,593 INFO SettingsFactory:321 - Cache provider: org.hibernate.cache.EhCacheProvider 16:27:06,656 INFO SettingsFactory:228 - Optimize cache for minimal puts: disabled 16:27:06,656 INFO SettingsFactory:237 - Structured second-level cache entries: disabled 16:27:06,687 INFO SettingsFactory:257 - Echoing all SQL to stdout 16:27:06,687 INFO SettingsFactory:261 - Statistics: disabled 16:27:06,687 INFO SettingsFactory:265 - Deleted entity synthetic identifier rollback: disabled 16:27:06,687 INFO SettingsFactory:279 - Default entity-mode: pojo 16:27:07,359 INFO SessionFactoryImpl:152 - building session factory 16:27:07,500 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/Owner/My%20Documents/Workspace/HibernateDemo20/lib/ehcache-1.1.jar!/ehcache-failsafe.xml 16:27:08,093 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured 16:27:08,093 INFO SessionFactoryImpl:379 - Checking 0 named queries Problem with next line?: 16:27:08,218 WARN JDBCExceptionReporter:71 - SQL Error: -22, SQLState: S0002 16:27:08,218 ERROR JDBCExceptionReporter:72 - Table not found in statement [select max(ID) from MyTable] could not fetch initial value Save failed.
So then, alternatively, I tried “mytable”. I changed the contents of Mytable.hbm.xml to:
<?xml version="1.0" encoding='UTF-8'?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <!-- DO NOT EDIT: This is a generated file that is synchronized --> <!-- by MyEclipse Hibernate tool integration. --> <!-- Created Thu Jan 26 09:21:27 EST 2006 --> <hibernate-mapping package="com.genuitec.hibernate"> <class name="Mytable" table="Mytable"> <id name="id" column="ID" type="integer"> <generator class="increment"/> </id> <property name="stuff" column="STUFF" type="string" /> </class> </hibernate-mapping>
Then I ran HibernateTest.java again and saw:
16:31:56,687 INFO Environment:464 - Hibernate 3.0.5 16:31:56,687 INFO Environment:477 - hibernate.properties not found 16:31:56,687 INFO Environment:510 - using CGLIB reflection optimizer 16:31:56,687 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling 16:31:56,765 INFO Configuration:1110 - configuring from resource: /hibernate.cfg.xml 16:31:56,765 INFO Configuration:1081 - Configuration resource: /hibernate.cfg.xml 16:31:57,062 INFO Configuration:444 - Mapping resource: com/genuitec/hibernate/Mytable.hbm.xml 16:31:57,187 INFO HbmBinder:260 - Mapping class: com.genuitec.hibernate.Mytable -> Mytable 16:31:57,203 INFO Configuration:1222 - Configured SessionFactory: null 16:31:57,203 INFO Configuration:875 - processing extends queue 16:31:57,203 INFO Configuration:879 - processing collection mappings 16:31:57,203 INFO Configuration:888 - processing association property references 16:31:57,203 INFO Configuration:917 - processing foreign key constraints 16:31:57,265 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!) 16:31:57,265 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20 16:31:57,265 INFO DriverManagerConnectionProvider:45 - autocommit mode: false 16:31:57,265 INFO DriverManagerConnectionProvider:80 - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hello 16:31:57,265 INFO DriverManagerConnectionProvider:86 - connection properties: {user=sa, password=****} 16:31:57,656 INFO SettingsFactory:77 - RDBMS: HSQL Database Engine, version: 1.8.0 16:31:57,656 INFO SettingsFactory:78 - JDBC driver: HSQL Database Engine Driver, version: 1.8.0 16:31:57,687 INFO Dialect:92 - Using dialect: org.hibernate.dialect.HSQLDialect 16:31:57,687 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions) 16:31:57,703 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended) 16:31:57,703 INFO SettingsFactory:125 - Automatic flush during beforeCompletion(): disabled 16:31:57,703 INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled 16:31:57,703 INFO SettingsFactory:136 - JDBC batch size: 15 16:31:57,703 INFO SettingsFactory:139 - JDBC batch updates for versioned data: disabled 16:31:57,703 INFO SettingsFactory:144 - Scrollable result sets: enabled 16:31:57,703 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): disabled 16:31:57,703 INFO SettingsFactory:160 - Connection release mode: null 16:31:57,703 INFO SettingsFactory:184 - Maximum outer join fetch depth: 1 16:31:57,703 INFO SettingsFactory:187 - Default batch fetch size: 1 16:31:57,703 INFO SettingsFactory:191 - Generate SQL with comments: disabled 16:31:57,703 INFO SettingsFactory:195 - Order SQL updates by primary key: disabled 16:31:57,703 INFO SettingsFactory:334 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory 16:31:57,703 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory 16:31:57,718 INFO SettingsFactory:203 - Query language substitutions: {} 16:31:57,718 INFO SettingsFactory:209 - Second-level cache: enabled 16:31:57,718 INFO SettingsFactory:213 - Query cache: disabled 16:31:57,718 INFO SettingsFactory:321 - Cache provider: org.hibernate.cache.EhCacheProvider 16:31:57,718 INFO SettingsFactory:228 - Optimize cache for minimal puts: disabled 16:31:57,718 INFO SettingsFactory:237 - Structured second-level cache entries: disabled 16:31:57,734 INFO SettingsFactory:257 - Echoing all SQL to stdout 16:31:57,734 INFO SettingsFactory:261 - Statistics: disabled 16:31:57,734 INFO SettingsFactory:265 - Deleted entity synthetic identifier rollback: disabled 16:31:57,734 INFO SettingsFactory:279 - Default entity-mode: pojo 16:31:57,859 INFO SessionFactoryImpl:152 - building session factory 16:31:57,875 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/Owner/My%20Documents/Workspace/HibernateDemo20/lib/ehcache-1.1.jar!/ehcache-failsafe.xml 16:31:58,171 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured 16:31:58,171 INFO SessionFactoryImpl:379 - Checking 0 named queries Problem with next line?: 16:31:58,234 WARN JDBCExceptionReporter:71 - SQL Error: -22, SQLState: S0002 16:31:58,234 ERROR JDBCExceptionReporter:72 - Table not found in statement [select max(ID) from Mytable] could not fetch initial value Save failed.
Finally, I changed back to MYTABLE and confirmed the original results. I changed the contents of Mytable.hbm.xml to:
<?xml version="1.0" encoding='UTF-8'?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <!-- DO NOT EDIT: This is a generated file that is synchronized --> <!-- by MyEclipse Hibernate tool integration. --> <!-- Created Thu Jan 26 09:21:27 EST 2006 --> <hibernate-mapping package="com.genuitec.hibernate"> <class name="Mytable" table="MYTABLE"> <id name="id" column="ID" type="integer"> <generator class="increment"/> </id> <property name="stuff" column="STUFF" type="string" /> </class> </hibernate-mapping>
Then I ran HibernateTest.java again and saw:
16:43:08,015 INFO Environment:464 - Hibernate 3.0.5 16:43:08,015 INFO Environment:477 - hibernate.properties not found 16:43:08,015 INFO Environment:510 - using CGLIB reflection optimizer 16:43:08,015 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling 16:43:08,093 INFO Configuration:1110 - configuring from resource: /hibernate.cfg.xml 16:43:08,093 INFO Configuration:1081 - Configuration resource: /hibernate.cfg.xml 16:43:08,406 INFO Configuration:444 - Mapping resource: com/genuitec/hibernate/Mytable.hbm.xml 16:43:08,562 INFO HbmBinder:260 - Mapping class: com.genuitec.hibernate.Mytable -> MYTABLE 16:43:08,578 INFO Configuration:1222 - Configured SessionFactory: null 16:43:08,578 INFO Configuration:875 - processing extends queue 16:43:08,578 INFO Configuration:879 - processing collection mappings 16:43:08,578 INFO Configuration:888 - processing association property references 16:43:08,578 INFO Configuration:917 - processing foreign key constraints 16:43:08,656 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!) 16:43:08,656 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20 16:43:08,656 INFO DriverManagerConnectionProvider:45 - autocommit mode: false 16:43:08,656 INFO DriverManagerConnectionProvider:80 - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hello 16:43:08,656 INFO DriverManagerConnectionProvider:86 - connection properties: {user=sa, password=****} 16:43:09,062 INFO SettingsFactory:77 - RDBMS: HSQL Database Engine, version: 1.8.0 16:43:09,062 INFO SettingsFactory:78 - JDBC driver: HSQL Database Engine Driver, version: 1.8.0 16:43:09,093 INFO Dialect:92 - Using dialect: org.hibernate.dialect.HSQLDialect 16:43:09,093 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions) 16:43:09,093 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended) 16:43:09,093 INFO SettingsFactory:125 - Automatic flush during beforeCompletion(): disabled 16:43:09,109 INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled 16:43:09,109 INFO SettingsFactory:136 - JDBC batch size: 15 16:43:09,109 INFO SettingsFactory:139 - JDBC batch updates for versioned data: disabled 16:43:09,109 INFO SettingsFactory:144 - Scrollable result sets: enabled 16:43:09,109 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): disabled 16:43:09,109 INFO SettingsFactory:160 - Connection release mode: null 16:43:09,109 INFO SettingsFactory:184 - Maximum outer join fetch depth: 1 16:43:09,109 INFO SettingsFactory:187 - Default batch fetch size: 1 16:43:09,109 INFO SettingsFactory:191 - Generate SQL with comments: disabled 16:43:09,109 INFO SettingsFactory:195 - Order SQL updates by primary key: disabled 16:43:09,109 INFO SettingsFactory:334 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory 16:43:09,109 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory 16:43:09,109 INFO SettingsFactory:203 - Query language substitutions: {} 16:43:09,109 INFO SettingsFactory:209 - Second-level cache: enabled 16:43:09,109 INFO SettingsFactory:213 - Query cache: disabled 16:43:09,109 INFO SettingsFactory:321 - Cache provider: org.hibernate.cache.EhCacheProvider 16:43:09,125 INFO SettingsFactory:228 - Optimize cache for minimal puts: disabled 16:43:09,125 INFO SettingsFactory:237 - Structured second-level cache entries: disabled 16:43:09,140 INFO SettingsFactory:257 - Echoing all SQL to stdout 16:43:09,140 INFO SettingsFactory:261 - Statistics: disabled 16:43:09,140 INFO SettingsFactory:265 - Deleted entity synthetic identifier rollback: disabled 16:43:09,140 INFO SettingsFactory:279 - Default entity-mode: pojo 16:43:09,281 INFO SessionFactoryImpl:152 - building session factory 16:43:09,281 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/Owner/My%20Documents/Workspace/HibernateDemo20/lib/ehcache-1.1.jar!/ehcache-failsafe.xml 16:43:09,578 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured 16:43:09,578 INFO SessionFactoryImpl:379 - Checking 0 named queries Problem with next line?: 16:43:09,640 WARN JDBCExceptionReporter:71 - SQL Error: -22, SQLState: S0002 16:43:09,640 ERROR JDBCExceptionReporter:72 - Table not found in statement [select max(ID) from MYTABLE] could not fetch initial value Save failed.
…What should I try next?
Riyad KallaMemberI really don’t like that warning: “No configuration found”, taht is what is worrying me.
Go edit your hibernate.cfg.xml file and comment out your mapping for MyTable, just comment out the whole line, then stop your app server, redeploy your app and start it back up. Does it barf totally or still say the same thing?
grb65aMemberI changed the contents of MTable.hbm.xml. I commented out the line you suggested as shown below.
<?xml version="1.0" encoding='UTF-8'?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <!-- DO NOT EDIT: This is a generated file that is synchronized --> <!-- by MyEclipse Hibernate tool integration. --> <!-- Created Thu Jan 26 09:21:27 EST 2006 --> <hibernate-mapping package="com.genuitec.hibernate"> <!-- <class name="Mytable" table="MYTABLE"> --> <id name="id" column="ID" type="integer"> <generator class="increment"/> </id> <property name="stuff" column="STUFF" type="string" /> </class> </hibernate-mapping>
I didn’t know what you meant by stop my application server (because I am not using one, unless by this you mean one embedded in Eclipse?) – so instead I just closed my connection and then opened it again (by going to the DB Explorer and closing all connections and then opened the connection once more).
I then ran HibernateTest.java and saw the following:
FATAL EXCEPTION OCCURRED. PROGRAM WILL EXIT.
Clicked OK.
And saw the following in the Console:18:01:49,890 INFO Environment:464 - Hibernate 3.0.5 18:01:49,890 INFO Environment:477 - hibernate.properties not found 18:01:49,906 INFO Environment:510 - using CGLIB reflection optimizer 18:01:49,906 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling 18:01:49,968 INFO Configuration:1110 - configuring from resource: /hibernate.cfg.xml 18:01:49,968 INFO Configuration:1081 - Configuration resource: /hibernate.cfg.xml 18:01:50,640 INFO Configuration:444 - Mapping resource: com/genuitec/hibernate/Mytable.hbm.xml %%%% Error Creating SessionFactory %%%% org.hibernate.MappingException: Error reading resource: com/genuitec/hibernate/Mytable.hbm.xml at org.hibernate.cfg.Configuration.addResource(Configuration.java:452) at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184) at org.hibernate.cfg.Configuration.configure(Configuration.java:1112) at com.genuitec.hibernate.SessionManager.currentSession(SessionManager.java:48) at com.genuitec.hibernate.HibernateTest.main(HibernateTest.java:13) Caused by: org.hibernate.MappingException: org.dom4j.DocumentException: Error on line 17 of document : The element type "hibernate-mapping" must be terminated by the matching end-tag "</hibernate-mapping>". Nested exception: The element type "hibernate-mapping" must be terminated by the matching end-tag "</hibernate-mapping>". at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:408) at org.hibernate.cfg.Configuration.addResource(Configuration.java:449) ... 7 more Caused by: org.dom4j.DocumentException: Error on line 17 of document : The element type "hibernate-mapping" must be terminated by the matching end-tag "</hibernate-mapping>". Nested exception: The element type "hibernate-mapping" must be terminated by the matching end-tag "</hibernate-mapping>". at org.dom4j.io.SAXReader.read(SAXReader.java:482) at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:398) ... 8 more 18:01:50,703 ERROR XMLHelper:59 - Error parsing XML: XML InputStream(17) The element type "hibernate-mapping" must be terminated by the matching end-tag "</hibernate-mapping>". 18:01:50,703 ERROR Configuration:407 - Could not configure datastore from input stream org.dom4j.DocumentException: Error on line 17 of document : The element type "hibernate-mapping" must be terminated by the matching end-tag "</hibernate-mapping>". Nested exception: The element type "hibernate-mapping" must be terminated by the matching end-tag "</hibernate-mapping>". at org.dom4j.io.SAXReader.read(SAXReader.java:482) at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:398) at org.hibernate.cfg.Configuration.addResource(Configuration.java:449) at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184) at org.hibernate.cfg.Configuration.configure(Configuration.java:1112) at com.genuitec.hibernate.SessionManager.currentSession(SessionManager.java:48) at com.genuitec.hibernate.HibernateTest.main(HibernateTest.java:13) Nested exception: org.xml.sax.SAXParseException: The element type "hibernate-mapping" must be terminated by the matching end-tag "</hibernate-mapping>". at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.dom4j.io.SAXReader.read(SAXReader.java:465) at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:398) at org.hibernate.cfg.Configuration.addResource(Configuration.java:449) at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184) at org.hibernate.cfg.Configuration.configure(Configuration.java:1112) at com.genuitec.hibernate.SessionManager.currentSession(SessionManager.java:48) at com.genuitec.hibernate.HibernateTest.main(HibernateTest.java:13) java.lang.NullPointerException at com.genuitec.hibernate.SessionManager.currentSession(SessionManager.java:56) at com.genuitec.hibernate.HibernateTest.main(HibernateTest.java:13) Exception in thread "main"
-
AuthorPosts