|
[
Permlink
| « Hide
]
Artur Karazniewicz added a comment - 31/Aug/04 12:05 PM
Updated file
* complete (?) support for HB3-alpha in sandbox
* added new "entity-name" related methods * added test suite for new methods Is there a place where we can download the nightly sandbox binary jar?
Unless it is added into sandbox You have to complite this for yourself.
Artur Note that Hibernate3 is still alpha. It's not feasible to ship support for alpha software in a Spring production release, therefore we can't include this in Spring proper until Hibernate3 becomes at least beta (which is likely to happen within the Spring 1.2 timeframe).
Juergen At 20 October 2004 I have tried to do exactly this:
This is all done within Eclipse, just in case it might matter. - Update spring from CVS. - Add hibernate3.jar and antlr-2.7.4 to the lib directory. - Add those jars to the buildpath. - Download your spring-hibernate3-final.tgz (52 kb) from this issue. - Copy the src and test directory to the sandbox directory within the spring project. - clean the project and do a complete rebuild. The problem is that I am getting a compile error on org.springframework.orm.hibernate3.HibernateTransactionObject: "Class must implement the inherited abstract method SmartTransactionObject.isRollbackOnly()" The weird thing is that I can not find any changes anywhere that this would have worked anywhere. Your spring-hibernate3.1 version doesn't include this method either and browsing through the CVS history I find nothing relevant is changed that could have any impact on this. Am I missing something obvious? It's easy enough to add this method, but I don't really know what this is supposed to be doing and what it should be doing and want to make sure it's done right. Thanks for the patch! Just cut and paste unimplemented method from spring's HibernateTemplate.
Artur The problem is that I am getting a compile error on org.springframework.orm.hibernate3.HibernateTransactionObject:
"Class must implement the inherited abstract method SmartTransactionObject.isRollbackOnly()" jou say "Just cut and paste unimplemented method from spring's HibernateTemplate." please tell me where ant what unimplemented method i cut and paste ? thank The patch seems need some changes to be compilable. I changed the patch now it seems compilable. Add fixed the isRollbackOnly problem and provides dummy implementation for hashCode and replace method in AbstractLobType class.
I have modified the code to work with the latest Hiberate3 code. It compiles fine, and all Unit tests pass. Thanks for the code for the latest Hibernate 3, I had a few of the minor issues mentioned (having to implement hashCode(), replace() - I used the -final bundle) and I also modified LocalSessionFactoryBean to use the Hibernate Annotations 3.0 alpha 2 package (along with supporting annotatedClasses and annotatedPackages). The code changes were pretty minor but happy to share if anyone wants them.
Uses the -final package provided and alters is slightly to use the new Hibernate 3 AnnotationConfiguration method.
The -annotations one I've uploaded will have rough edges, and no work was put into refactoring the base packages, cleaning up comments etc. Caveat empor but let me know if you have any troubles... ideally a new hibernate3 Spring package in CVS would help things along so ppl can make a start.
I'm trying to compile this against hibernate3 beta3 but it doesn't work.
1) The method afterTransactionCompletion(boolean, Transaction) in the type SessionImplementor is not applicable for the arguments (boolean) SessionFactoryUtils.java (src/org/springframework/orm/hibernate3 line 701) It seems that the signature of that method changed just after hibernate 3b2: now it needs a second argument including the Transaction. 2) LocalTransactionManagerLookup import a net.sf.hibernate class instead of the org.hibernate one! 3) AbstractLobType does "import org.springframework.orm.hibernate.LocalSessionFactoryBean" instead of "import org.springframework.orm.hibernate3.LocalSessionFactoryBean" (notice the "3" in the hibernate package name) Can you guys please fix the problem so we can integrate Spring with the latest Hibernate3 version? I am just wondering that Hibernate3 has already been delivered beta4, Spring is supposed to support it currently.
Noddy I think that hibernate b4 is the same as beta 3 from spring views.
The latest code attached does not compile due to the few code I've already commented in a previous comment. I know that hibernate 3 allow more powerful operations that hibernate2. One for all: if I remember correctly in H3 you can avoid the session.close() call. I think many H3 improvements could bring a cleaner integration with spring but I also think that this integration should be done by someone that knows well h3 and spring internals. My current plan is to do a fresh port of the most recent Hibernate 2.1 support in "orm.hibernate" to the "orm.hibernate3" package, as soon as Spring 1.1.5 has been released (currently scheduled for Feb 28).
Hibernate3 support will be officially released soon after, in Spring 1.2 RC1 (currently scheduled for mid March). It will already be available right after the 1.1.5 release in nightly 1.2-RC1-dev snapshots. This should coincide nicely with the first Hibernate3 release candidate (with the Hibernate3 API frozen). If there is an urgent need for earlier Hibernate3 support, I would suggest uploading a preliminary add-on jar file to JIRA. Juergen Well, it's not that you can't avoid the Session.close call: As far as I understand, all you can get is automatic closing at *JTA* transaction completion - for *each* Session you open during a JTA transaction.
So even with Hibernate3, Spring's resource management adds a lot of value: using the *same* Session during a transaction, even for multiple operations (multiple getSession calls) - both for JTA transactions and local transactions. Consequently, I expect Spring's support for Hibernate3 to be very analogous to the current support for Hibernate 2.1, both in terms of resource management and in terms of HibernateTemplate operations. I agree that Spring's Hibernate3 support should work with the native Hibernate3 API, not the classic API that they keep for backwards compatibility - even if this means dropping a couple of operations on the Hibernate 2.1 HibernateTemplate. Juergen For HibernateB4, in SessionFactoryUtils, you should use
((SessionImplementor) session).afterTransactionCompletion( status == STATUS_COMMITTED, sessionHolder.getTransaction()); in the method public void afterCompletion(int status) I guess.. Jonas The hibernate operations should be changed for hibernate 3. I personnaly don't like so much all the "find" operations... I'd rather like to have a similar interface than the hibernate session with createQuery and createCriteria.
the merge operations should be added to HibernateOperations
There is an updated version of the hibernate 3 bindings called spring-hibernate3-upd.zip. I added a setting to enable the JMX management which allows you to see hibernate 3 statistics.
<property name="JMXEnabled"> <value>true</value> </property> Is required in the applicationContext.xml in the hibernate sessionFactory bean to enable statistics on hibernate and also register the hibernate server into the JVM built-in JMX server. I also added the merge operation. This compiles and works with the RC1. I have attached a file LocalAnnotationSessionFactoryBean.
It basically completes the integration of Hibernate3, Spring, and Hibernate3 annotations. It is an extension of the standard spring LocalSessionFactoryBean, which creates an AnnotationConfiguration instead of a standard Configuration, and has a new property "annotatedClasses". The list of classes will be added to the configuration via the "addAnnotatedClass" as part of the overridden postProcessConfiguration method. You can now put the following in a spring config file, and be able to use annotated classes instead of hibernate mapping files. <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalAnnotationSessionFactoryBean"> ... <property name="annotatedClasses"> <list> <value>MyObjectImpl</value> </list> </property> ... </bean> FYI: In regards to my attachment of the LocalAnnotationHibernateSessionFactory class, i'm not expecting it to be distributed in the same jar with all the other files, but i think it should be in it's own optional jar along with any other JDK 5 features. I understand the need to keep backward compatibility, but it doesn't mean that the early adopters should suffer, and putting it in it's own jar will appease both groups.
are the patches associated with this issue going to be the code that gets put into the sandbox, or are there plans to do something different ?
Also, what is the timeframe for Hibernate 3 support - it has a release candidate now. I've committed Hibernate3 support ("orm.hibernate3" package) to Spring CVS, as fresh port of the current Hibernate 2.1 support. This should be available in the nightly Spring 1.2-dev snapshot by Monday.
The first official release that includes Hibernate3 support will be Spring 1.2 RC1, due in about two weeks. This will also include JMX support and other new features. Juergen Currently this is only copy of old "Session" interface. Please add new methods from org.hibernate.Session interface.
The Hibernate3 support as currently in CVS already features the new "persist" and "merge" operations, so should be pretty complete in terms of Hibernate3 operations.
We don't have operations for "entity names" yet, that is, Hibernate3's support for Maps etc. I don't intend to add such methods, actually: Spring focuses on rich domain objects, so persistent Maps as DAO layer arguments don't really fit in. Of course, any Hibernate3 Session method can be called in a HibernateCallback, where the native Hibernate Session will be exposed. The full Hibernate Query and Criteria facilities are available there. The operations on HibernateTemplate are just conveniences. Alternatively, you can also work with direct Session access (SessionFactoryUtils.getSession or HibernateDaoSupport.getSession), which is particularly straightforward if you can guarantee execution within a transaction (where no close call is necessary, because the Session will be managed by the transaction). With Hibernate3, you could even code such direct Session access without special exception handling - provided that you're willing to let the now unchecked HibernateException through at your DAO layer. We still recommend throwing an implementation-independent exception like Spring's DataAccessException at the DAO layer, though. Juergen I just looked at the files in the repository... There should be some way to enable hibernate JMX support. I think LocalSessionFactoryBean is the proper place to do it (I added that code in my zip file). It is a important feature especially regarding spring support of JMX.
We don't need to build support for the JMX StatisticsService into LocalSessionFactoryBean itself. Spring's JMX support can be leveraged to expose the StatisticsService in a declarative way: just a define a corresponding MBeanExporter.
<bean class="org.springframework.jmx.export.MBeanExporter"> <property name="beans"> <map> <entry key="org.hibernate.jmx.StatisticsService:type=StatisticsService"><ref bean="statisticsService"/></entry> </map> </property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> ... </bean> <bean id="statisticsService" class="org.hibernate.jmx.StatisticsService"> <property name="sessionFactory"><ref bean="SessionFactory"/></property> </bean> Alternatively, rely on MBeanExporter's autodetection of MBeans and implicit naming through the bean name: <bean class="org.springframework.jmx.export.MBeanExporter"/> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> ... </bean> <bean name="org.hibernate.jmx.StatisticsService:type=StatisticsService" class="org.hibernate.jmx.StatisticsService"> <property name="sessionFactory"><ref bean="SessionFactory"/></property> </bean> Juergen Completed for 1.2 RC1. Full Hibernate3 support as expected; support for Hibernate's JMX statistics service through Spring's new JMX support rather than hard-wired.
No direct Hibernate3 annotations support yet: we want to avoid building the main Spring download on JDK 1.5 for the time being. Hibernate's alpha annotation support can be activated through the new "configurationClass" property on LocalSessionFactoryBean, with the annotated packages and annotated classes getting specified in the standard "hibernate.cfg.xml" file: <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation"> <value>classpath:hibernate.cfg.xml</value> </property> <property name="configurationClass"> <value>org.hibernate.cfg.AnnotationConfiguration</value> </property> </bean> Alternatively, create a custom subclass of LocalSessionFactoryBean and register your annotated packages and classes in a custom "postProcessConfiguration" implementation, casting the Configuration object to AnnotationConfiguration. Juergen I'm missing something or I cannot see "entityName"-related methods. This is very usefull feature and IMHO should be available via spring's HibernateTemplate.
Is there any Spring support for Hibernate's new row-level security (session filters)? When I open a new session, I want to call session.enableFilter() with some transaction-specific security context information (like current user), but there doesn't appear to be a clean way to ensure that any call to the session factory's getSession() guarantees that the session returned has the appropriate filters set on it.
What I'm doing as a workaround is overriding createHibernateTemplate() in my HibernateDaoSupport subclass to wrap the session factory used by the template in a delegating SessionFactory that ensures the session filters are set for any calls to getSession(*). That keeps me from having to modify any of the Spring source. Does that sound like a decent way to go? I was thinking the alternative would be to add some callback pattern in the SessionFactoryUtils (a la the interceptor) that's called at create session time, but I'm reluctant to modify the Spring source given my level of unfamiliarity with the guts of Spring. The createQuery/createCriteria methods on HibernateTemplate have often been misunderstood and misused: They were intended to be called *within HibernateCallback implementations*, to allow to prepare Query objects in special ways. This was also the reason why those methods threw HibernateException rather than DataAccessException.
This usage style was clearly outlined in the javadoc, but most people nevertheless called them in their DAOs directly, handling HibernateExceptions in custom ways etc. For this reason, those methods have been deprecated in Spring 1.1.x, and now removed in Spring 1.2. The Hibernate Session exposed to a HibernateCallback implementation is now proxied and applies special preparing of created Query objects. Therefore, simply use Session.createQuery/createCriteria within a HibernateCallback instead - the native Hibernate API -, usually within an anonymous HibernateCallback class: List result = getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Query query = session.createQuery("some HQL string"); ... return query.list(); } }); Juergen | |||||||||||||||||||||||||||||||||||||||||||||||||