facebook

Trouble using Hibernate & HSQLDB

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 10 posts - 16 through 25 (of 25 total)
  • Author
    Posts
  • #245471 Reply

    grb65a
    Member

    Oops. I didn’t follow your last instructions right.
    You didn’t ask me to changed the contents of Mytable.hbm.xml. You asked me to comment out the mapping statement in hibernate.cfg.xml. So I restored Mytable.hbm.xml and instead commented out the line you suggested in hibernate.cfg.xml as shown below:

    <?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:MYTABLE</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>

    I then saw the following in response:

    18:24:19,000  INFO Environment:464 - Hibernate 3.0.5
    18:24:19,000  INFO Environment:477 - hibernate.properties not found
    18:24:19,000  INFO Environment:510 - using CGLIB reflection optimizer
    18:24:19,000  INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling
    18:24:19,078  INFO Configuration:1110 - configuring from resource: /hibernate.cfg.xml
    18:24:19,078  INFO Configuration:1081 - Configuration resource: /hibernate.cfg.xml
    18:24:19,375  INFO Configuration:1222 - Configured SessionFactory: null
    18:24:19,390  INFO Configuration:875 - processing extends queue
    18:24:19,390  INFO Configuration:879 - processing collection mappings
    18:24:19,390  INFO Configuration:888 - processing association property references
    18:24:19,390  INFO Configuration:917 - processing foreign key constraints
    18:24:19,390  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
    18:24:19,390  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
    18:24:19,390  INFO DriverManagerConnectionProvider:45 - autocommit mode: false
    18:24:19,406  INFO DriverManagerConnectionProvider:80 - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:MYTABLE
    18:24:19,406  INFO DriverManagerConnectionProvider:86 - connection properties: {user=sa, password=****}
    18:24:19,796  INFO SettingsFactory:77 - RDBMS: HSQL Database Engine, version: 1.8.0
    18:24:19,796  INFO SettingsFactory:78 - JDBC driver: HSQL Database Engine Driver, version: 1.8.0
    18:24:19,828  INFO Dialect:92 - Using dialect: org.hibernate.dialect.HSQLDialect
    18:24:19,859  INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
    18:24:19,875  INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    18:24:19,875  INFO SettingsFactory:125 - Automatic flush during beforeCompletion(): disabled
    18:24:19,875  INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled
    18:24:19,875  INFO SettingsFactory:136 - JDBC batch size: 15
    18:24:19,875  INFO SettingsFactory:139 - JDBC batch updates for versioned data: disabled
    18:24:19,875  INFO SettingsFactory:144 - Scrollable result sets: enabled
    18:24:19,890  INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): disabled
    18:24:19,890  INFO SettingsFactory:160 - Connection release mode: null
    18:24:19,890  INFO SettingsFactory:184 - Maximum outer join fetch depth: 1
    18:24:19,890  INFO SettingsFactory:187 - Default batch fetch size: 1
    18:24:19,890  INFO SettingsFactory:191 - Generate SQL with comments: disabled
    18:24:19,890  INFO SettingsFactory:195 - Order SQL updates by primary key: disabled
    18:24:19,890  INFO SettingsFactory:334 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    18:24:19,890  INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory
    18:24:19,890  INFO SettingsFactory:203 - Query language substitutions: {}
    18:24:19,890  INFO SettingsFactory:209 - Second-level cache: enabled
    18:24:19,890  INFO SettingsFactory:213 - Query cache: disabled
    18:24:19,890  INFO SettingsFactory:321 - Cache provider: org.hibernate.cache.EhCacheProvider
    18:24:19,890  INFO SettingsFactory:228 - Optimize cache for minimal puts: disabled
    18:24:19,890  INFO SettingsFactory:237 - Structured second-level cache entries: disabled
    18:24:19,906  INFO SettingsFactory:257 - Echoing all SQL to stdout
    18:24:19,906  INFO SettingsFactory:261 - Statistics: disabled
    18:24:19,906  INFO SettingsFactory:265 - Deleted entity synthetic identifier rollback: disabled
    18:24:19,906  INFO SettingsFactory:279 - Default entity-mode: pojo
    18:24:20,046  INFO SessionFactoryImpl:152 - building session factory
    18:24:20,062  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
    18:24:20,078  INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
    18:24:20,078  INFO SessionFactoryImpl:379 - Checking 0 named queries
    Problem with next line?:
    Unknown entity: com.genuitec.hibernate.Mytable
    Save failed.
    #245501 Reply

    Riyad Kalla
    Member

    This is a doozy. Can you generate create table scripts for your table (MyTable) and save it in a text file, add that to the project, then export the whole project to a ZIP file (File > Export > To Archive) and then send it to support@genuitec.com ATTN Riyad and I’ll take a look at it.

    #245517 Reply

    grb65a
    Member

    I’ll be very glad to – but how do I generate table scripts? (I’m not an experienced programmer and the gaps in my knowledge are pretty big, I apologize). Alternatively, the “(SLIGHTLY BROKEN) TUTORIAL” that I included in a previous post included every single keystroke I entered including my CREATE TABLE statement:

    CREATE TABLE MyTable(id INT primary key, stuff varchar(255));

    Is the above all that you are looking for?

    Again, I’ll be glad to zip up everything I’ve done and send it to you, but I think if you just repeat the steps of the “(SLIGHTLY BROKEN) TUTORIAL”, you will be able to reproduce my results in maybe 20 minutes tops… it describes everything I did, beginning with downloading hsqldb_1_8_0_1.zip… I’ve repeated it so many times with so many variations I know it doesn’t take long to do…

    #245518 Reply

    Riyad Kalla
    Member

    I’ll follow your tutorial, but if it works for me, then you owe me a beer 😉

    #245530 Reply

    grb65a
    Member

    Heck, I’ll be glad to send you a case of beer. And good beer at that. But I don’t think it’s going to work – because I just successfully got it to work with mySQL!!! This means either that:

    A. There is a bug in some code somewhere related to the hsqldb database
    A. Or there is an error in my tutorial specifically related to connecting to it.

    Below you will find my tutorial rewritten reflecting how I successfully got it to work for MySQL:

    A Complete Tutorial for Using Eclipse 3.1 and MyEclipse4.0 to create a Java Project using Hibernate to write to a MySQL 5.0.18 Database

    Installed MySQL Database

    1. Downloaded mysql-5.0.18-win32.zip

    2. Moved it to:

    c:\ mysql-5.0.18-win32 zip\mysql-5.0.18-win32.zip

    3. Extracted it to:

    c:\mysql-5.0.18-win32 Extracted\

    4. Clicked on setup.exe.

    5. Did typical installation

    Destination Folfer: C:\Program Files\MySQL\MySQL Server 5.0\

    6. Configured MySQL using the MySQL Server Instance Configuration Wizard 1.0.8.
    Selected detailed configuration
    Next
    Developer machine
    next
    Multifunctional database
    default settings
    c: Installation Path
    Next
    Decision Support
    Next
    Enable TCPIP networking
    Port 3306
    Enable strict mode
    next
    standard character set
    Next
    Install as windows service
    New Root Password: aaa
    next
    execute
    Norton Internet Security Dialog popped up: Always Allow connection on all ports
    Finish

    Tested MySQL Database

    7. From Command Prompt, typed:

    C:\mysql\bin\mysqlshow -u root -p mysql

    When prompted for root password, typed aaa

    Saw the following positive result: a list of tables.

    Installed MySQL Connector/J 3.1

    1. Downloaded mysql-connector-java-3.1.12.zip

    2. Moved it to:

    c:\MySQL-Connector-Java 3112 zip\ mysql-connector-java-3.1.12.zip

    3. Extracted it to:

    c:\MySQL-Connector-Java 3112Extracted\

    Created MyEclipse Connection Profile

    4. Opened Eclipse 3.1 with MyEclipse 4.0 installed

    5. Clicked Window/OpenPerspective/Other/MyEclipse Database Explorer

    6. Clicked Window/Preferences/MyEclipse/Database Explorer/Drivers and Selected MySQL Connector/J Driver and then Edit.

    Name: MySQL Connector/J Driver
    Example URL: jdbc:mysql://localhost/products
    Java Class Path: c:\eclipse\startup.jar
    Driver libraries: c:\MySQL-Connector-Java 3112Extracted\ MySQL-Connector-Java-3.1.12\MySQL-Connector-Java-3.1.12-bin.jar
    Driver class name: com.mysql.jdbc.Driver

    Clicked OK, Apply, OK.

    1. Clicked on Database Explorer New Connection Icon and created:

    Profile Name: MySQL Connection – ConnectorJ – 01
    Show Drivers: All
    Driver: MySQL Connector/J Driver
    URL: jdbc:mysql://localhost/products
    UserName: root
    Password: aaa
    Open On Eclipse Startup: <Unchecked>
    Prompt for Password: checked

    Clicked Next:

    Selected Display all Schemas

    Clicked Finish.

    2. With the Connection Profile just created selected, clicked on Open Connection Icon. Then, with Autocommit checked, clicked OK in response to LogIn dialog.
    3. Got error – unknown database products.

    4. Clicked on Database Explorer New Connection Icon and changed database name:

    Profile Name: MySQL Connection – ConnectorJ – 01
    Show Drivers: All
    Driver: MySQL Connector/J Driver
    URL: jdbc:mysql://localhost/mysql
    UserName: root
    Password: aaa
    Open On Eclipse Startup: <Unchecked>
    Prompt for Password: checked

    Result: Was Connected

    5. Clicked on “+” next to Connection and selected:

    Connected to MySQL Connection – ConnectorJ – 01

    6. Was able to see tables in the DB Explorer.

    7. Examined them a bit.

    Tested MySQL Connection

    8. Right Clicked on:

    Connected to MySQL Connection – ConnectorJ – 01

    Then clicked New SQL Editor.

    9. From SQL Editor, made sure that in the field at the top of the Editor, the MySQL Connection – ConnectorJ – 01 connection was selected.

    10. Then entered:

    CREATE TABLE firsttable(id INT primary key, stuff varchar(255));

    Then clicked ‘Running Man’ Icon:

    No error messages.

    11. But then could not find table firsttable in DB Explorer.
    12. Then entered:

    CREATE TABLE secondtable(id INT primary key, stuff varchar(255));

    13. Then in the DB Explorer, beneath mysql, right clicked on TABLE, and clicked refresh. This resulted in the number of tables going from 17 to 19 in the Table Info view.

    14. Was then able to see that firsttable and secondtable were both beneath TABLE along with the other preestablished tables.

    15. Then, in the SQL Editor, entered:

    INSERT INTO firsttable (ID, STUFF) VALUES (‘1’, ‘hello’);

    16. Then selected the firsttable, clicked refresh, and then in the Table Info View, clicked preview, and was able to see the row entered.

    Created Project Using MySQL Connection

    17. Clicked Window/OpenPerspective/Other/Java(default).

    18. Clicked File/New/Project.

    19. Selected Java Project and clicked Next.

    Project Name: HibernateDemo25
    Create New Project in Workspace
    Use Default Compiler
    Checked Create Separate Source and Output Folders
    Clicked Next

    Saw in the next Dialog:
    Default Output Folder: HibernateDemo25/bin
    Clicked Finish

    20. With the Project HibernateDemo25 selected, Clicked MyEclipse/Add Hibernate Capabilities.

    Hibernate Specification: Hibernate 3
    Library Folder: /lib
    Checked: Append Hibernate libraries to project classpath
    Hibernate Config File: New

    Clicked Next

    Configuration Folder Path: /HibernateDemo25/src
    Configuration File Name: hibernate.cfg.xml

    Clicked Next

    Checked: Create SessionFactory Class
    Session Factory Class: com.genuitec.hibernate.SessionManager
    Source Folder: /src

    Clicked Finish

    21. In hibernate.cfg.xml, configured database connection profile:

    Selected: Use JDBC Driver
    DB Connect Profile: MySQL Connection – ConnectorJ – 01
    URL: jdbc:mysql://localhost/mysql
    Driver: com.mysql.jdbc.Driver
    UserName: root
    Password: aaa
    Dialect: MySQL
    Did not click Copy JDBC Driver and Add to Classpath
    Saved file.
    Closed file.

    22. Clicked Window/OpenPerspective/Other/MyEclipse Database Explorer

    23. Selected secondtable, right clicked and clicked Create Hibernate Mapping.

    Location: /HibernateDemo25/src/com/genuitec/hibernate
    Base Persistence Class: <blank>
    ID Generator: Increment
    Types: Use Hibernate Types
    Checked: Update Hibernate Configuration File.

    Clicked Finish.

    24. Confirmed in Project HibernateDemo25, existence under src/com/genuitec/hibernate:

    Abstract secondtable.java
    secondtable.java
    secondtable.hbm.xml
    SessionManager.java

    25. In /src/com.genuitec.hibernate, created a Java Class HibernateTest by selecting File/New/Class then:

    Source Folder: HibernateDemo25/src
    Package: com.genuitec.hibernate
    Name: HibernateTest
    Superclass: java.lang.Object
    Checked public static void main(String[]args)
    Checked Inherited abstract methods
    Finish

    26. 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 
    Secondtable sss = new Secondtable (); 
    // 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 
    } 
    } 
    } 
    } 
    

    27. In the Package Explorer, selected HibernateDemo25, and then imported the following (with Create selected folders only checked):

    C:\MYSQL-Connector-Java 3112Extracted\mysql-connector-java-3.1.12\lib\mysql-connector-java-3.1.12bin.jar

    Then 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.

    28. Selected HibernateTest and clicked Run/Run as Java Application.

    29. 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?:
    No Problem in previous line if you see this.
    Save successful.

    Confirmed Success from DBExplorer

    30. Clicked Window/OpenPerspective/Other/MyEclipse Database Explorer

    31. Then in the DB Explorer, beneath mysql, right clicked on TABLE, and clicked refresh.

    32. Then selected the secondtable, and then in the Table Info View, clicked preview, and was able to see the row entered.

    #245556 Reply

    Riyad Kalla
    Member

    How did you setup HSQL to accept more than one connection? When I walk through your tutorial generation fails because the DB Explorer has the current connection to the DB, so the additional connection that is attempted to be made to generate the mappings fails for me.

    #245557 Reply

    grb65a
    Member

    I just confirmed that if I close all connections in the DB Explorer and exit the DB Explorer by going to the Java Perspective, then run HibernateTest, it still doesn’t work. I am guessing from your post that you must have tried this too, it being easy to try, and saw the same exact result (or you would presumably be telling me that you had success by doing so).

    What I am hoping is either that you can figure out how to get something written to an hsqldb database (and what you did differently to do so…), or that my suspicion that there may be a bug somewhere is correct…

    #245558 Reply

    Riyad Kalla
    Member

    I was actually asking you how you got HSQL to accept more than 1 connection. When I tried to generate the mappings (per the steps in your tutorial) I got an exception letting me know that HSQL won’t let any more connections occur. So I’m curious how you even walked through your own tutorial.

    #245559 Reply

    grb65a
    Member

    Where in the tutorial am I opening multiple connections? Other than maybe not specifically closing a single connection in the DB Explorer ahead of running HibernateTest? I suppose if you can tell me exactly where my tutorial opens multiple connections, we could eliminate the extra connection(s) and then see if things work?

    #245560 Reply

    grb65a
    Member

    Hey, just for the heck of it, I tried to reproduce what you saw. I copied my Connection Profile and created two identical connection profiles. And then I opened both and did not see an error message. And then leaving them open, I executed HibernateTest and saw the following – I did not see the exception you say you saw, unless you can tell me it is something below I am not understanding…:

    21:26:33,296 INFO Environment:464 – Hibernate 3.0.5
    21:26:33,296 INFO Environment:477 – hibernate.properties not found
    21:26:33,296 INFO Environment:510 – using CGLIB reflection optimizer
    21:26:33,312 INFO Environment:540 – using JDK 1.4 java.sql.Timestamp handling
    21:26:33,390 INFO Configuration:1110 – configuring from resource: /hibernate.cfg.xml
    21:26:33,390 INFO Configuration:1081 – Configuration resource: /hibernate.cfg.xml
    21:26:33,812 INFO Configuration:1222 – Configured SessionFactory: null
    21:26:33,812 INFO Configuration:875 – processing extends queue
    21:26:33,812 INFO Configuration:879 – processing collection mappings
    21:26:33,812 INFO Configuration:888 – processing association property references
    21:26:33,812 INFO Configuration:917 – processing foreign key constraints
    21:26:33,828 INFO DriverManagerConnectionProvider:41 – Using Hibernate built-in connection pool (not for production use!)
    21:26:33,828 INFO DriverManagerConnectionProvider:42 – Hibernate connection pool size: 20
    21:26:33,828 INFO DriverManagerConnectionProvider:45 – autocommit mode: false
    21:26:33,828 INFO DriverManagerConnectionProvider:80 – using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:MYTABLE
    21:26:33,828 INFO DriverManagerConnectionProvider:86 – connection properties: {user=sa, password=****}
    21:26:34,421 INFO SettingsFactory:77 – RDBMS: HSQL Database Engine, version: 1.8.0
    21:26:34,421 INFO SettingsFactory:78 – JDBC driver: HSQL Database Engine Driver, version: 1.8.0
    21:26:34,453 INFO Dialect:92 – Using dialect: org.hibernate.dialect.HSQLDialect
    21:26:34,500 INFO TransactionFactoryFactory:31 – Using default transaction strategy (direct JDBC transactions)
    21:26:34,500 INFO TransactionManagerLookupFactory:33 – No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    21:26:34,500 INFO SettingsFactory:125 – Automatic flush during beforeCompletion(): disabled
    21:26:34,500 INFO SettingsFactory:129 – Automatic session close at end of transaction: disabled
    21:26:34,500 INFO SettingsFactory:136 – JDBC batch size: 15
    21:26:34,500 INFO SettingsFactory:139 – JDBC batch updates for versioned data: disabled
    21:26:34,500 INFO SettingsFactory:144 – Scrollable result sets: enabled
    21:26:34,500 INFO SettingsFactory:152 – JDBC3 getGeneratedKeys(): disabled
    21:26:34,500 INFO SettingsFactory:160 – Connection release mode: null
    21:26:34,500 INFO SettingsFactory:184 – Maximum outer join fetch depth: 1
    21:26:34,500 INFO SettingsFactory:187 – Default batch fetch size: 1
    21:26:34,500 INFO SettingsFactory:191 – Generate SQL with comments: disabled
    21:26:34,500 INFO SettingsFactory:195 – Order SQL updates by primary key: disabled
    21:26:34,500 INFO SettingsFactory:334 – Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    21:26:34,515 INFO ASTQueryTranslatorFactory:21 – Using ASTQueryTranslatorFactory
    21:26:34,515 INFO SettingsFactory:203 – Query language substitutions: {}
    21:26:34,515 INFO SettingsFactory:209 – Second-level cache: enabled
    21:26:34,515 INFO SettingsFactory:213 – Query cache: disabled
    21:26:34,515 INFO SettingsFactory:321 – Cache provider: org.hibernate.cache.EhCacheProvider
    21:26:34,515 INFO SettingsFactory:228 – Optimize cache for minimal puts: disabled
    21:26:34,515 INFO SettingsFactory:237 – Structured second-level cache entries: disabled
    21:26:34,515 INFO SettingsFactory:257 – Echoing all SQL to stdout
    21:26:34,515 INFO SettingsFactory:261 – Statistics: disabled
    21:26:34,515 INFO SettingsFactory:265 – Deleted entity synthetic identifier rollback: disabled
    21:26:34,515 INFO SettingsFactory:279 – Default entity-mode: pojo
    21:26:34,890 INFO SessionFactoryImpl:152 – building session factory
    21:26:34,906 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/Copy%20of%20HibernateDemo20/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
    21:26:34,921 INFO SessionFactoryObjectFactory:82 – Not binding factory to JNDI, no JNDI name configured
    21:26:34,937 INFO SessionFactoryImpl:379 – Checking 0 named queries
    Problem with next line?:
    Unknown entity: com.genuitec.hibernate.Mytable
    Save failed.

Viewing 10 posts - 16 through 25 (of 25 total)
Reply To: Trouble using Hibernate & HSQLDB

You must be logged in to post in the forum log in