Hi to all, i have a problem, the problem is the next:
I'm developing a JAVA application using Struts 1 and Hibernate 3.2 with DB Oracle. I've generated the entities without problems (using simple POJOS with xml mapping files). In Struts 1 i developed a component that initializes SessionFactory if it doesn't exists and initializes a Session object, in the next way:
Code:
SessionFactory hibernateSessionFactory = HibernateUtil.getSessionFactory();
Session hSession = hibernateSessionFactory .openSession();
And i have the next code that contains user authentication logic:
Code:
Query hQuery = hSession.createQuery("FROM ComUsuario WHERE codusr = :codusr AND clave = :clave AND estado = 'ACT'");
hQuery.setParameter("codusr", loginForm.getCodusr());
hQuery.setParameter("clave", loginForm.getClave());
List lstCoincidencias = hQuery.list();
ComUsuario objUsuario = (ComUsuario)lstCoincidencias.get(0);
Query hQuery2 = hSession.createQuery("SELECT DISTINCT r FROM ComRolesUsuario u, IN (u.comRol) r " +
" WHERE u.comUsuario = :usuario AND r.estado = 'ACT'");
hQuery2.setParameter("usuario", objUsuario);
List lstRolesUsr = hQuery2.list();
Query hQuery3 = hSession.createQuery("SELECT o FROM ComOpcionesMenu o, IN (o.comAccesosMenus) a " +
" WHERE a.comRol IN (:lstRoles) AND o.estado = 'ACT' " +
" AND o.comOpcionesMenu = NULL ");
hQuery3.setParameter("lstRoles", lstRolesUsr);
List lstOpcUsr = hQuery3.list();
But when it tries to run the third Query in this line:
Code:
List lstOpcUsr = hQuery3.list();
It gives me the next error:
Code:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.datasoft.zara.comis.orm.ComRol.idrol
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:183)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3524)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3240)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:218)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:87)
at org.hibernate.loader.hql.QueryLoader.bindNamedParameters(QueryLoader.java:517)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1576)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2144)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
at org.hibernate.loader.Loader.list(Loader.java:2023)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
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 com.datasoft.zara.comis.struts.actions.LoginAction.iniciarSesion(LoginAction.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at org.apache.struts.actions.LookupDispatchAction.execute(LookupDispatchAction.java:252)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:857)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:565)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
... 47 more
I realized about this line of error stacktrace:
Code:
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
And i don't understand why i get that, but if i don't use the LIKE clause, it works!
The hibernate.cfg.xml is the next:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:MYSID</property>
<property name="hibernate.connection.username">1234</property>
<property name="hibernate.connection.password">1234</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<mapping resource="com/enterprise/somet/comis/orm/ComAccesosMenu.hbm.xml"/>
<mapping resource="com/enterprise/somet/comis/orm/ComRolesUsuario.hbm.xml"/>
<mapping resource="com/enterprise/somet/comis/orm/ComUsuario.hbm.xml"/>
<mapping resource="com/enterprise/somet/comis/orm/ComRol.hbm.xml"/>
<mapping resource="com/enterprise/somet/comis/orm/ComOpcionesMenu.hbm.xml"/>
</session-factory>
</hibernate-configuration>
And hibernate.reveng.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<schema-selection match-schema="TEST"/>
<table-filter match-name="COM_OPCIONES_MENU"/>
<table-filter match-name="COM_ROL"/>
<table-filter match-name="COM_USUARIO"/>
<table-filter match-name="COM_ROLES_USUARIO"/>
<table-filter match-name="COM_ACCESOS_MENU"/>
</hibernate-reverse-engineering>