[jboss-user] [Installation, Configuration & DEPLOYMENT] - Re: Maven + Embedded EJB + JPA +EJB 3.0 getting Null name

r_sudh do-not-reply at jboss.com
Tue Aug 7 00:01:17 EDT 2007


Took me a while to get this but here it is:

The persistence.xml should look almost exactly like below:

<persistence>
  | 	<persistence-unit name="myPU">
  | 	<jta-data-source>java:/MyDB</jta-data-source>
  | 		<properties>					
  | 			<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" />
  | 			<property name="hibernate.hbm2ddl.auto" value="update" />							
  | 		</properties>		
  | 	</persistence-unit>
  | </persistence>

Each tag should be in one single line with no line breaks. The Null name I was getting is most likely a bug in parsing this persistence.xml file with line breaks.

Also, since I was coming from a toplink background I found that the data source has to be name "java:/MyDB" as opposed to "jdbc/MyDB"

Then make sure you have the corresponding data source defined in embedded-jboss-beans.xml as below

<bean name="MyDB" class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
  |       <property name="driverClass">com.mysql.jdbc.Driver</property>
  |       <property name="connectionURL">jdbc:mysql://dev1:3306/mydb?user=root&password=hello</property>
  |       <property name="jndiName">java:/MyDB</property>
  |       <property name="transactionManager"><inject bean="TransactionManager"/></property>
  |       <property name="cachedConnectionManager"><inject bean="CachedConnectionManager"/></property>
  |       <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
  |    </bean>
  | 


Finally here is a method that will test your code:

  | public void create() throws Exception {
  | 		Owner owner = new Owner();
  | 		OwnerData ownerData = new OwnerData();
  | 		ownerData.setName("Test Company");
  | 		ownerData.setContact("Richard");
  | 		ownerData.setPhone("979-777-7777");
  | 		owner.setOwnerData(ownerData);
  | 
  | 		EJB3StandaloneBootstrap.boot(null);
  | 		EJB3StandaloneBootstrap.scanClasspath();
  | 
  | 		InitialContext ctx = getInitialContext();
  | 
  | 		OwnerDAO dao = (OwnerDAO) ctx.lookup("OwnerDAOBean/local");
  | 		dao.create(owner);
  | 		EJB3StandaloneBootstrap.shutdown();
  | 	} 

I was having problems trying to get the lookup to work when the container was being started by a BeforeGroups method. But I've save that for another post. Once you get it all working it's pretty cool :)

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4071420#4071420

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4071420



More information about the jboss-user mailing list