[jboss-user] [JBoss Seam] - Entity not persisting from within a Servlet Filter

brentgfox do-not-reply at jboss.com
Sun Jan 7 11:27:09 EST 2007


I'm attempting to integrate a servlet filter I wrote into a new seam application, and I can't seem to get it to persist an entity bean. I've created an EntityManager from an EntityManagerFactory, and can execute queries against it, but it doesn't seem to persist the data.

I've tried a few combinations - but to no avail.

>From my servlet filter:


  | public void doFilter(ServletRequest request, ServletResponse response,
  | 			FilterChain chain) throws IOException, ServletException
  | 	{
  |          ...			
  |                try
  | 			{
  | 				InitialContext ctx = new InitialContext();
  | 				emf = (EntityManagerFactory) ctx.lookup("java:/userDatabase");
  | 				EntityManager em = emf.createEntityManager();
  | 				try
  | 				{
  | 					System.out.println("Attempting ejb query.");
  | 					List existing = em.createQuery("from User").getResultList();
  | 					Iterator ie = existing.iterator();
  | 					while (ie.hasNext())
  | 					{
  | 						ie.next();
  | 						System.out.println("Object Found");
  | 					}
  | 
  |                                         // And the code that doesn't work.
  | 					// User u = new User("tester");
  | 					// em.persist(user);
  | 					
  | 					
  | ...
  | 

And from my persistence.xml file


  | ...
  |     <persistence-unit name="userDatabase">
  |       <provider>org.hibernate.ejb.HibernatePersistence</provider>
  |       <jta-data-source>java:/Postgres</jta-data-source>
  |       <properties>
  |          <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
  | 		 <property name="jboss.entity.manager.factory.jndi.name" value="java:/userDatabase"/>	
  | 		</properties>
  | 	</persistence-unit>
  | ...
  | 

And from my web.xml


  | ...
  | 	<!--  Persistence Context Ref -->
  | 	<persistence-context-ref>
  | 	   <persistence-context-ref-name>persistence/UserDatabase</persistence-context-ref-name>
  | 	   <persistence-unit-name>userDatabase</persistence-unit-name>
  | 	</persistence-context-ref>
  | ...
  | 

The query returns objects - but when I attempt to persist the User entity - nothing happens. No exceptions, no results, no record in the database.

I'm running JBoss 4.0.5GA, with ejb3, Seam 1.1, connecting to a PostgreSQL 8.1 database. 

Anyone have an idea why it will not persist?

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

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



More information about the jboss-user mailing list