Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.0
Mapping documents:
<hibernate-mapping>
<class name="com.serena.dashboard.security.users.DashboardUser" table="SECURITY_PRINCIPAL">
<id name="id" column="PRINCIPAL_ID" />
<property name="userName" column="FULL_PATH" />
<property name="role"
formula="( select sp.FULL_PATH from SECURITY_PRINCIPAL sp where sp.PRINCIPAL_ID = (select sur.ROLE_ID from SECURITY_USER_ROLE sur where sur.USER_ID = PRINCIPAL_ID) )"/>
<property name="fullName"
formula="( select ppv.PROPERTY_VALUE from PREFS_PROPERTY_VALUE ppv where ppv.PROPERTY_NAME='user.name.full' and ppv.NODE_ID = (select pn.NODE_ID from PREFS_NODE pn where pn.NODE_NAME='userinfo' and pn.FULL_PATH = CONCAT(FULL_PATH, '/userinfo') ) )"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
---------------------- UserManager Java class -----------------------------
Session hiberSession = null;
hiberSession = JetspeedHibernateUtil.getSession();
hiberSession.beginTransaction();
String hqlStatement = "from DashboardUser user where user.userName like ? and user.role like ? and user.fullName like ? ";
List result = null;
try {
Query query = hiberSession.createQuery(hqlStatement);
query.setString(0, "/user/" + searchCriteria.getUserName() );
query.setString(1, "/role/" + searchCriteria.getRole() );
query.setString(2, searchCriteria.getUserFullName());
result = query.list();
}
catch( Throwable t ){
t.printStackTrace();
}
-------------------- JSP displaying user list has commitTransaction -------------
<%com.serena.dashboard.hibernate.JetspeedHibernateUtil.commitTransaction();%>
<%com.serena.dashboard.hibernate.JetspeedHibernateUtil.closeSession();%>
Full stack trace of any exception that occurs: NA
Name and version of the database you are using: Oracle 9i
The generated SQL (show_sql=true):
Hibernate: select dashboardu0_.PRINCIPAL_ID as PRINCIPAL1_5_, dashboardu0_.FULL_
PATH as FULL2_5_, ( select sp.FULL_PATH from SECURITY_PRINCIPAL sp where sp.PRIN
CIPAL_ID = (select sur.ROLE_ID from SECURITY_USER_ROLE sur where sur.USER_ID = d
ashboardu0_.PRINCIPAL_ID) ) as formula0_, ( select ppv.PROPERTY_VALUE from PREFS
_PROPERTY_VALUE ppv where ppv.PROPERTY_NAME='user.name.full' and ppv.NODE_ID = (
select pn.NODE_ID from PREFS_NODE pn where pn.NODE_NAME='userinfo' and pn.FULL_P
ATH = CONCAT(dashboardu0_.FULL_PATH, '/userinfo') ) ) as formula1_ from SECURITY
_PRINCIPAL dashboardu0_ where (dashboardu0_.FULL_PATH like ?) and (( select sp.F
ULL_PATH from SECURITY_PRINCIPAL sp where sp.PRINCIPAL_ID = (select sur.ROLE_ID
from SECURITY_USER_ROLE sur where sur.USER_ID = dashboardu0_.PRINCIPAL_ID) ) lik
e ?) and (( select ppv.PROPERTY_VALUE from PREFS_PROPERTY_VALUE ppv where ppv.PR
OPERTY_NAME='user.name.full' and ppv.NODE_ID = (select pn.NODE_ID from PREFS_NOD
E pn where pn.NODE_NAME='userinfo' and pn.FULL_PATH = CONCAT(dashboardu0_.FULL_P
ATH, '/userinfo') ) ) like ?)
Debug level Hibernate log excerpt:
------------------------------------------------------------------------------------
I am using hibernate to search Jetspeed users based on username, his full name and assigned role. Since Jetspeed does not have wildcard search yet, we decided to go against the database directly using hibernate. The updates to Jetspeed users happen through Jetspeed's own User and Role managers. Thus there are two separate applications updating same database. When I change role for a particular user using Jetspeed RoleManager, it gets updated properly in the database but hibernate still returns old role value for that user unless I restart Tomcat.
I have disabled second level caching using
<property name="hibernate.cache.use_second_level_cache">false</property>
Sorry for the big post but wanted to include as much information as possible.
Thanks.
Meghana