facebook

EJB3 with JTA in MyEclipse 6.0

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #276836 Reply

    jwalkerc
    Member

    With the 6.0 release, you guys have done a terrific job in enhancing the product and bringing documentation up to date.

    I have been trying to do a simplistic EJB3 entity and deploying it to Glassfish 2 and testing with a simple test class. I did the JPA tutorial and it worked like a champ.

    Next I decided to do the EJB3. I created an EJB project and specified it as EJB3 with JPA support. On the next view, I check JTA support, specify and driver and catalog/schema. I am using MySQL. I am still not sure what the JNDI data source links back to. Whatever I put there is placed into the jta-data-source tag of the persistence.xml file. Next I do reverse engineering to get my entity bean. I deploy the app and start up Glassfish. Once it starts deploying my app, its not happy.

    WARNING: javax.naming.NameNotFoundException
    java.lang.RuntimeException: javax.naming.NameNotFoundException
    at com.sun.enterprise.server.PersistenceUnitInfoImpl._getJtaDataSource(PersistenceUnitInfoImpl.java:283)

    I’m thinking that there needs to be something more in the persistence.xml.

    #276847

    Loyal Water
    Member

    Hi jwalkerc,
    Can you go to MyEclipse > Installation Summary > Installation Details andd paste the information here for me.

    Also, can you paste the entire error log here for me.

    #276855

    jwalkerc
    Member

    The critical missing piece is Glassfish. Anyone who is trying to do EJB3 in Glassfish with MyEclipse 6.0 and not using Derby, should review my steps below:

    1. If you’re going to do an EJB3 in Glassfish, there’s some set up required on Glassfish. In my case, I am using MySQL for the database.
    2. Add the mysql driver jar file to your domain (domain1) under lib/ext. Add this directory to your startup classpath.
    3. Login to admin console of Glassfish. Go to Resources -> JDBC -> Connection Pools. Click New. Enter mysql for Name, java.sql.DataSource for Resource Type and MySql for Database Vendor. Click Next. Select com.mysql.jdbc.jdbc2.optional.MysqlDataSource for Datsource Classname.
    4. Next go to Resource -> JDBC -> JDBC Resources. Click New. Enter JNDI Name: java/mysql, Pool Name: mysql, and provide a description.

    This will setup the necessary connections in Glassfish.

    The default created persistence.xml will only contain:

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <persistence xmlns=”http://java.sun.com/xml/ns/persistence&#8221;
    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
    xsi:schemaLocation=”http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&#8221;
    version=”1.0″>
    <persistence-unit name=”<your project name>PU”
    transaction-type=”JTA”>
    <jta-data-source>
    whatever name you setup as the JNDI in step four above
    </jta-data-source>
    </persistence-unit>
    </persistence>

    You need to add the following properties:

    <properties>
    <!–Use the java2db feature –>
    <property name=”toplink.ddl-generation”
    value=”drop-and-create-tables” />
    <!– Generate the sql specific to Derby database –>
    <property name=”toplink.target-database”
    value=”oracle.toplink.essentials.platform.database.MySQL4Platform” />
    </properties>

    This will result in:

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <persistence xmlns=”http://java.sun.com/xml/ns/persistence&#8221;
    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
    xsi:schemaLocation=”http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&#8221;
    version=”1.0″>

    <persistence-unit name=”<your project name>PU”
    transaction-type=”JTA”>
    <jta-data-source>java/mysql</jta-data-source>
    <properties>
    <!–Use the java2db feature –>
    <property name=”toplink.ddl-generation”
    value=”drop-and-create-tables” />
    <!– Generate the sql specific to Derby database –>
    <property name=”toplink.target-database”
    value=”oracle.toplink.essentials.platform.database.MySQL4Platform” />
    </properties>
    </persistence-unit>
    </persistence>

    #276861

    Loyal Water
    Member

    jwalkerc,
    Thank you for this post. Im sure it will help the other developers working with EJB3 and Glassfish.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: EJB3 with JTA in MyEclipse 6.0

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