facebook

Session EJBs and Hinernate data access

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #226624 Reply

    – System Setup ——————————-
    Operating System and version: WindowsXP, SP2
    Eclipse version: 3.0.1
    Eclipse build id: 200409161125
    Fresh Eclipse install (y/n): y
    If not, was it upgraded to its current version using the update manager?
    Other installed external plugins:
    None
    Number of plugins in the <eclipse>/plugins directory that begin with org.eclipse.pde.*: 8
    MyEclipse version: 3.8.3
    Eclipse JDK version: j2sdk1.4.2_06
    Application Server JDK version: j2sdk1.4.2_06
    Are there any exceptions in the Eclipse log file? Dont think so

    If this is a DB related question please answer the following:

    RDBMS vendor and version: MySQL 4.1
    JDBC driver vendor and version, and access type (thin, type-2, etc): commysql.jdbc.Driver
    Connection URL: jdbc:mysql://localhost:3306/libraryweb3
    Eclipse error logs related to com.genuitec.eclipse.sqlexplorer packages:
    Cant find any

    – Message Body ——————————-
    I am trying to develop a small teaching example based upon the oft-used Library application and comprising a Struts project, a Session EJB used as a Businesss Delegate (CRUD and Borrow and Return functions) and a Hibernate O/R mapping to a MySql database. Deployed to JBoss 4, my example works ok when the Business Delegate is a POJO but not when I substitute a Session Bean (and its Transaction Management) for the POJO. [I am not using an Enterprise Application Project.]

    The deployment descriptors are shown below with my manual additions surrounded by double exclamation marks (i.e. !!). [Note. The additions have been copied by me from an external tutorial example which employed a Session EJB and Hibernate but not with the MyEclipse IDE support.]

    [hibernate,cfg.xml]
    <hibernate-configuration>
    <session-factory>
    <!– properties –>
    <property name=”connection.username”>root</property>
    <property name=”connection.url”>jdbc:mysql://localhost:3306/libraryweb3</property>
    <property name=”dialect”>net.sf.hibernate.dialect.MySQLDialect</property>
    <property name=”connection.password”>p088502z</property>
    <property name=”connection.driver_class”>com.mysql.jdbc.Driver</property>
    !!<property name=”connection.datasource”>java:/libraryweb3</property>
    <property name=”transaction.manager_lookup_class”>
    net.sf.hibernate.transaction.JBossTransactionManagerLookup</property>
    <property name=”transaction.factory.class”>
    net.sf.hibernate.transaction.JTATransactionFactory</property>!!

    <!– mapping files –>
    <mapping resource=”de/laliluna/library/Book.hbm.xml”/>
    <mapping resource=”de/laliluna/library/Customer.hbm.xml”/>
    </session-factory>
    </hibernate-configuration>

    [ejb-jar.xml]
    <ejb-jar>
    <description><![CDATA[No Description.]]></description>
    <display-name>Generated by XDoclet</display-name>
    <enterprise-beans>
    <session >
    <description><![CDATA[Description for MyLibrary]]></description>
    <display-name>Name for MyLibrary</display-name>
    <ejb-name>MyLibrary</ejb-name>
    <home>mylibrary.interfaces.MyLibraryHome</home>
    <remote>mylibrary.interfaces.MyLibrary</remote>
    <ejb-class>mylibrary.ejb.MyLibrarySession</ejb-class>
    <session-type>Stateless</session-type>
    <transaction-type>Container</transaction-type>
    </session>
    </enterprise-beans
    <assembly-descriptor>
    “<container-transaction>
    <method>
    <ejb-name>MyLibrary</ejb-name>
    <method-name>*</method-name>
    </method>
    <trans-attribute>RequiresNew</trans-attribute>
    </container-transaction>”
    </assembly-descriptor>
    </ejb-jar>

    [jboss.xml]
    <jboss>
    <enterprise-beans>
    <session>
    <ejb-name>MyLibrary</ejb-name>
    <jndi-name>/ejb/MyLibraryHome</jndi-name>
    <method-attributes>
    </method-attributes>
    </session>
    </enterprise-beans>

    <resource-managers>
    </resource-managers>
    </jboss>

    [mysql-ds.xml]
    <datasources>
    <local-tx-datasource>
    !!<jndi-name>libraryweb3</jndi-name>
    <connection-url>jdbc:mysql://localhost:3306/libraryweb3</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>root</user-name>
    <password>p088502z</password>!!

    <!– corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) –>
    <metadata>
    <type-mapping>mySQL</type-mapping>
    </metadata>
    </local-tx-datasource>
    </datasources>

    In the Struts Action subclass, the relevant code snippet for the Session EJB is
    .
    .
    .
    try {
    InitialContext context = new InitialContext();
    MyLibraryHome libraryHome = (MyLibraryHome) context.lookup(MyLibraryHome.JNDI_NAME);
    MyLibrary library = libraryHome.create();
    bookListForm.setBooks(library.getAllBooks());
    }
    .
    .
    .
    The console output and exception stack traces relating to the code failure are as follows.

    10:39:52,429 INFO [Configuration] configuring from resource: /hibernate.cfg.xml
    10:39:52,429 INFO [Configuration] Configuration resource: /hibernate.cfg.xml
    10:39:52,617 INFO [Configuration] Mapping resource: de/laliluna/library/Book.hbm.xml
    10:39:52,820 ERROR [Configuration] Could not compile the mapping document
    net.sf.hibernate.MappingException: duplicate import: Book
    at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:85)
    at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:126)
    at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:221)
    at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1256)
    at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
    at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
    at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
    at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1013)
    at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:969)
    at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:897)
    at de.laliluna.library.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:50)
    at mylibrary.ejb.MyLibraryBean.getAllBooks(MyLibraryBean.java:109)
    etc.

    10:56:25,987 INFO [STDOUT] %%%% Error Creating SessionFactory %%%%

    10:39:52,945 INFO [STDOUT] net.sf.hibernate.MappingException: Error reading resource: de/laliluna/library/Book.hbm.xml
    at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:339)
    at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1013)
    at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:969)
    at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:897)
    at de.laliluna.library.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:50)
    at mylibrary.ejb.MyLibraryBean.getAllBooks(MyLibraryBean.java:109)
    etc.
    Caused by: net.sf.hibernate.MappingException: duplicate import: Book
    at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:85)
    at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:126)
    at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:221)
    at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1256)
    at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
    at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
    at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
    … 80 more

    10:41:54,742 ERROR [LogInterceptor] RuntimeException in method: public abstract de.laliluna.library.Book[] mylibrary.interfaces.MyLibrary.getAllBooks() throws java.rmi.RemoteException:
    java.lang.NullPointerException
    at de.laliluna.library.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:58)
    at mylibrary.ejb.MyLibraryBean.getAllBooks(MyLibraryBean.java:109)
    etc.

    10:41:54,757 INFO [STDOUT] java.rmi.ServerException: RuntimeException; nested exception is: java.lang.NullPointerException

    10:41:54,757 INFO [STDOUT] at org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:385)
    etc.

    #226648 Reply

    Riyad Kalla
    Member

    Moving to OT > Soft Dev.

    For future reference this is really a Hibernate question, not a MyEclipse question. However it would seem that your Book.hbm.xml file is possibly invalid OR defines multiple hibernate mappings (looks like it might define Book twice?). Do you want to paste it’s contents so we can take a look?

    Also, try and use code blocks (code button at bottom) when wrapping code, it will keep its formatting and be easier to read.

    #226667 Reply

    <?xml version=”1.0″?>
    <!DOCTYPE hibernate-mapping PUBLIC
    “-//Hibernate/Hibernate Mapping DTD 2.0//EN”
    http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd&#8221; >

    <!– DO NOT EDIT: This is a generated file that is synchronized –>
    <!– by MyEclipse Hibernate tool integration. –>
    <!– Created Tue Feb 22 11:11:41 GMT 2005 –>
    <hibernate-mapping package=”de.laliluna.library”>

    <class name=”Book” table=”book”>
    <id name=”id” column=”id” type=”java.lang.Integer”>
    <generator class=”native”/>
    </id>

    <property name=”title” column=”title” type=”java.lang.String” />
    <property name=”author” column=”author” type=”java.lang.String” />
    <property name=”available” column=”available” type=”java.lang.Boolean” not-null=”true” />

    <many-to-one name=”customer” column=”customer_fk” class=”Customer” />
    </class>

    </hibernate-mapping>

    #226675 Reply

    Riyad Kalla
    Member

    I don’t have any ideas.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Session EJBs and Hinernate data access

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