Hello!
We have a problem with jacc. We always get the stacktrace listed below when we try to fetch some records from the database. We made a 5-hours-debug-session and found, that the session instance has the jacc-preloadlisteners installed, which are called when a new record is fetched from database and before it is converted to the POJO Object. We can't imagine why jacc is enabled.
Hibernate version:
Hibernate Core 3.2.1
Hibernate Entity-Manager 3.2.0
Hibernate Annotations 3.2.0
Eclipse RCP 3.2.1
Mapping documents:
Mapping is done with Annotations
Code between sessionFactory.openSession() and session.close():
My Business Object which is called, it creates a new PersistenceContext which holds the EntityManager:
Code:
public static boolean login(final String user) {
final PersistenceContext tx = new PersistenceContext();
try {
tx.begin();
AppUser appUser = new AppUserDAO(tx).findByCodeId(user);
tx.commit();
if (appUser != null) {
PropertiesStore.getDefault().setAppUser(appUser);
return true;
} else {
return false;
}
} catch (Exception e) {
log.error(e.getMessage());
if (tx.isActive()) {
tx.rollback();
}
return false;
} finally {
tx.close();
}
}
My own Persistence Context, which holds the EntityManager:
Code:
public class PersistenceContext {
private Logger log = new Logger(PersistenceContext.class);
private EntityManager entityManager;
public PersistenceContext() {
BundleContext context = Activator.getDefault().getBundleContext();
ServiceReference reference = context.getServiceReference(HibernateEntityManagerFactory.class.getName());
EntityManagerFactory factory = (EntityManagerFactory)context.getService(reference);
log.debug("Get service Hibernate EntityManagerFactory");
entityManager = factory.createEntityManager();
}
public void close() {
if (entityManager != null && entityManager.isOpen()) {
entityManager.close();
}
BundleContext context = Activator.getDefault().getBundleContext();
ServiceReference reference = context.getServiceReference(HibernateEntityManagerFactory.class.getName());
if (reference.getUsingBundles().length > 1) {
context.ungetService(reference);
log.debug("Unget service Hibernate EntityManagerFactory");
}
}
public EntityManager getEntityManager() {
return entityManager;
}
public void begin() {
if (entityManager != null) {
entityManager.getTransaction().begin();
log.debug("Transaction started.");
}
}
public void commit() {
if (entityManager != null && entityManager.getTransaction().isActive()) {
entityManager.getTransaction().commit();
log.debug("Transaction commited.");
}
}
public void rollback() {
if (entityManager != null && entityManager.getTransaction().isActive()) {
entityManager.getTransaction().rollback();
log.debug("Transaction rolled back");
}
}
public boolean isActive() {
if (entityManager != null && entityManager.getTransaction().isActive()) {
return true;
}
return false;
}
My DAO Object, which is called from the Business Object:
Code:
public AppUser findByCodeId(String codeId) {
try {
Query query = entityManager.createQuery(
"select c from " + modelClass.getName() + " as c");// where c.codeId=:codeId");
//query.setParameter("codeId",codeId);
//Object o = query.getSingleResult();
//AbstractQueryImpl q = (QueryImpl)query;
List list = query.getResultList();
return null;
} catch (Exception e) {
log.error(e.getMessage(),e);
return null;
}
}
The creation of the EntityManagerFactory, straight forward:
Code:
public Object getService(Bundle bundle, ServiceRegistration registration) {
/* first we check if a database connection is available */
if (!JdbcConnection.testConnection()) {
log.debug("Error creating Hibernate EntityManagerFactory, database connection failed.");
return null;
}
/* start hibernate and make an entity-manager factory */
try {
Properties p = new PropertyFileConfigurator(IConstants.CONFIG_HIBERNATE).getProperties();
Ejb3Configuration config = new Ejb3Configuration();
if (!p.isEmpty()) {
config.setProperties(p);
} else {
throw new Exception("Properties for Hibernate are empty.");
}
ArrayList<Class> classes = (ArrayList<Class>)getPOJOs();
for (Class c : classes) {
config.addAnnotatedClass(c);
}
HibernateEntityManagerFactory factory =
(HibernateEntityManagerFactory)config.buildEntityManagerFactory();
log.debug("Hibernate EntityManagerFactory created.");
return factory;
} catch (Exception e) {
log.error(e.getMessage());
return null;
}
}
Full stack trace of any exception that occurs:java.lang.IllegalArgumentException: unknown handler key
at javax.security.jacc.PolicyContext.getContext(PolicyContext.java:280)
at org.hibernate.secure.JACCPermissions$3.getContextSubject(JACCPermissions.java:88)
at org.hibernate.secure.JACCPermissions.getContextSubject(JACCPermissions.java:97)
at org.hibernate.secure.JACCPermissions.checkPermission(JACCPermissions.java:36)
at org.hibernate.secure.JACCPreLoadEventListener.onPreLoad(JACCPreLoadEventListener.java:30)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:125)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2211)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:388)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
at org.dseas.base.dao.AppUserDAO.findByCodeId(AppUserDAO.java:30)
at org.dseas.business.intro.LoginBO.login(LoginBO.java:23)
at org.dseas.ui.rcp.intro.LoginComposite.login(LoginComposite.java:102)
at org.dseas.ui.rcp.intro.LoginComposite.access$0(LoginComposite.java:100)
at org.dseas.ui.rcp.intro.LoginComposite$1.mouseDown(LoginComposite.java:75)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:133)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1914)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:419)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.dseas.ui.rcp.Application.run(Application.java:23)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336)
at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
at org.eclipse.core.launcher.Main.run(Main.java:977)
at org.eclipse.core.launcher.Main.main(Main.java:952)
Name and version of the database you are using:Oracle 10g
The Hibernate Configuration FileNote, that jacc is disabled.
Code:
# Driver class and database dialect
hibernate.connection.driver_class = oracle.jdbc.driver.OracleDriver
hibernate.dialect = org.hibernate.dialect.Oracle9Dialect
# Database connection url
hibernate.connection.url = jdbc:oracle:thin:@localhost:1521:xe
# User name, password, schema
hibernate.connection.username = dseas
hibernate.connection.password = dseas
hibernate.default_schema = DSEAS
hibernate.jacc.enabled=false
# JDBC connection pool
hibernate.c3p0.min_size=1
hibernate.c3p0.max_size=5
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50
So we are dueless what we should do, as a similar configuration in another environment works without problem. Is there a way to disable jacc programatically?
If you need further information please let me know.
Best Regards,
Christoph