- This topic has 3 replies, 2 voices, and was last updated 17 years, 9 months ago by
Loyal Water.
-
AuthorPosts
-
jwalkercMemberWith 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.
October 12, 2007 at 7:35 am #276847
Loyal WaterMemberHi 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.
October 12, 2007 at 10:34 am #276855
jwalkercMemberThe 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”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd”
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”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd”
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>October 12, 2007 at 11:02 am #276861
Loyal WaterMemberjwalkerc,
Thank you for this post. Im sure it will help the other developers working with EJB3 and Glassfish. -
AuthorPosts