facebook

Hibernate Tutorial Session is closed

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #213462 Reply

    lucientaylor
    Member

    I have been working through the Hibernate DB tutorial. I am getting ‘Hibernate error – Session is closed’ after the first page has displayed (i.e. following any subsequent hits). I suspect this is a JDBC config. thing. The Hibernate docs for Tomcat refer to DB connection using JNDI. Do you have any examples of JNDI driver configuration on the MyEclipse side?

    #213515

    support-jeff
    Member

    I do not have any example code for setting up JNDI access, although it ought to be pretty simple to do so using the ‘Add Hibernate Capabilities’ or ‘New Hibernate Configuration’ wizards. Just have to follow the docs on Tomcat for setting up a JNDI context.

    Is this not working for you now just using straight up JDBC driver connections? Are you running servlets in Single Thread Mode? Trying to open and close connections using the SessionFactory more than once per thread/request? Please send me your code and I can take a look – zip it up and send it to jeff@genuitec.com

    #213520

    snpe
    Member

    This is example with hibernate.cfg.xml

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <!DOCTYPE hibernate-configuration
    PUBLIC “-//Hibernate/Hibernate Configuration DTD 2.0//EN”
    http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd”&gt;

    <hibernate-configuration>
    <session-factory >
    <property name=”hibernate.connection.datasource”>java:/comp/env/jdbc/JNDINAME</property>
    <property name=”hibernate.default_schema”>MYSCHEMA</property>
    <property name=”dialect”>net.sf.hibernate.dialect.XXXDialect</property>

    <property name=”hibernate.show_sql”>true</property>
    <property name=”hibernate.use_outer_join”>true</property>

    <mapping resource=”mypackagae/MyClass.hbm”.xml />

    </session-factory>

    </hibernate-configuration>

    You need set your jndi name,your dialect and your mapping files

    regards

    #213560

    lucienhome
    Member

    I had a bug in my HibernateSessionFactory. I couldn’t spot this until I got JNDI working. For reference here is my JNDI conf

    <session-factory>
    <!– properties –>
    <property name=”connection.datasource”>java:comp/env/jdbc/MyDB</property>
    <property name=”show_sql”>false</property>
    <property name=”dialect”>net.sf.hibernate.dialect.MySQLDialect</property>

    <!– mapping files –>
    <mapping resource=”uk/ltd/taylorsmith/app/bo/Item.hbm.xml”/>

    </session-factory>

    that’s all I needed. The params requested in the wizard are confusing without the docs.

    #213567

    Riyad Kalla
    Member

    Thank you for sharing lucien, I hope others users find it helpful.

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Hibernate Tutorial Session is closed

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