[jboss-user] [EJB 3.0] - Re: what happen with my entity bean , need expert help

jfheintz do-not-reply at jboss.com
Fri Jul 27 02:45:14 EDT 2007


No I have followed your instruction, here is my code:

MySite.java:

package test;

@javax.persistence.Entity
@javax.persistence.Table(name="SI_SITE")
public class MySite {

@javax.persistence.Column(name="siteId")
@javax.persistence.Id
private java.lang.Long siteId;

@javax.persistence.Column(name="name")
private java.lang.String name;
@javax.persistence.Column(name="description")
private java.lang.String description;
@javax.persistence.Column(name="staticSite")
private boolean staticSite;
@javax.persistence.Column(name="status")
private int status;

public MySite() {
}

... getter and setter for the previous attributes

}


The client (part of a session bean):

EjbLocator ejbLocator=EjbLocator.getLocator();
MySite siteEJB3=ejbLocator.find(MySite.class, new Long(1));

EjbLocator.java:

public class EjbLocator {

	@PersistenceContext(unitName="StatInfoUnit")
	private EntityManager manager;	

	private static Context ctx;

	private static EjbLocator instance = new EjbLocator();

	private EjbLocator() {
		try {
			ctx = new InitialContext();
		} catch (NamingException e) {
			logger.error(e.getMessage());
		}
	}

	public static EjbLocator getLocator() {
		return instance;
	}

	private  T getEjb(Class ejbClass, String name) {
		try {
			T service = (T) new InitialContext().lookup("Statinfo/" + name
					+ "/local");
			return service;
		} catch (NamingException e) {
			return null;
		}
	}


	public  T find(Class ejb3Class, Object id) {
		return manager.find(ejb3Class, id);
	}
	
	public void persist(Object ejb3Object) {
		manager.persist(ejb3Object);
	}
	
}

I have a persistence.xml in META-INF dir:


    <persistence-unit name="StatInfoUnit">
       <jta-data-source>java:/StatInfoDS</jta-data-source>
    	 <!-- Explicitly define mapping file path, else Hibernate won't find the default -->
		 <mapping-file>META-INF/orm.xml</mapping-file>
      test.MySite
		 <!-- exclude-unlisted-classes=true: Prevent annotation scanning. In this app we are purely driven by orm.xml -->
		 <exclude-unlisted-classes>false</exclude-unlisted-classes>
       org.hibernate.ejb.HibernatePersistence
       
           
           
       
    </persistence-unit>


I have a orm.xml in META-INF dir:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings
  xmlns="http://java.sun.com/xml/ns/persistence/orm"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
  version="1.0">
<persistence-unit-metadata>
</persistence-unit-metadata>
</entity-mappings>

Deployment is OK but the exception (Nullpointer) occurs when the client part is called, any idea?

Thanks a lot for your help,

JF

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

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



More information about the jboss-user mailing list