I've a session bean wich on his @PostConstruct callback method tries to load
the database on first time.
The problem is that i'm constantly getting an error of type "EntityManager must
be access within a transaction". I've tried to get a user transaction from
the injected session context but I'don't get it working.
this is the code I've
@PostConstruct
public void postConstructCallback()
{
System.out.println("LanguageBean. postConstructCallback().
Started.");
EntityManager manager;
Integer intTableSize;
// EntityTransaction transaction = manager.getTransaction();
//UserTransaction transaction = context.getUserTransaction();
//manager =
emf.createEntityManager(PersistenceContextType.EXTENDED);
try
{
//Query query = manager.createQuery("SELECT
count(language) FROM Language language");
//intTableSize = (Integer) query.getSingleResult();
/*
if ( transaction != null && intTableSize == 0 )
{
transaction.begin();
this.loadDatabase(manager);
}
*/
System.out.println(
"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY" );
System.out.println( this.getAll().size() );
System.out.println(
"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY" );
}
catch (Exception e)
{
/*
try {
transaction.rollback();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SecurityException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SystemException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
*/
System.out.println("LanguageBean.
postConstructCallback(). Rollback due to errors.");
e.printStackTrace();
}
finally
{
}
System.out.println("LanguageBean. postConstructCallback(). Ended.");
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3931468#3931468
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3931468
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user