tag:blogger.com,1999:blog-10088978.post559516894408228890..comments2022-06-28T19:59:10.771-07:00Comments on Nothing to see here...: Adding Generics to the AbstractHibernateDaoRay Kruegerhttp://www.blogger.com/profile/06110480752501115735noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-10088978.post-21974952960699232752009-04-06T10:55:00.000-07:002009-04-06T10:55:00.000-07:00I've always annotated the class as readonly, and m...I've always annotated the class as readonly, and made specific methods not-read only.<BR/><BR/>Creating sessions on the fly can be dangerous if bad code creeps in to your application that causes sessions to be created in the wrong places.Ray Kruegerhttps://www.blogger.com/profile/06110480752501115735noreply@blogger.comtag:blogger.com,1999:blog-10088978.post-65282901405759909702009-04-06T08:53:00.000-07:002009-04-06T08:53:00.000-07:00Thanks for the response. I did dig in some more an...Thanks for the response. I did dig in some more and found that it has nothing to do with non-container ..<BR/><BR/>I'll explain the situation:<BR/><BR/>1) For Services which were writing into database, I annotated them with @transactional. For the ones , which just read, I omitted the annotation<BR/><BR/>2) The error occurs when I call these services which doesn't have annotation as it is clear Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-10088978.post-79989891028324380942009-04-03T07:45:00.000-07:002009-04-03T07:45:00.000-07:00I really don't know what you mean by container-man...I really don't know what you mean by container-managed or not. Either way, I'll try to address your question.<BR/><BR/>You've got a basic Spring/Hibernate configuration problem. Even if you were using the old Spring HibernateTemplate you'd get the same error. You have no transaction or hibernate interceptors in the path before the call to currentSession() that tell Spring to create a Hibernate Ray Kruegerhttps://www.blogger.com/profile/06110480752501115735noreply@blogger.comtag:blogger.com,1999:blog-10088978.post-64762576691047006302009-04-03T07:37:00.000-07:002009-04-03T07:37:00.000-07:00Hi,I tried using your abstractHibernateDao. It wor...Hi,<BR/><BR/>I tried using your abstractHibernateDao. It works perfectly well in container-managed situation.. But, when I am not using any container, it throws an exception "org.hibernate.HibernateException: No Hibernate Session bound to thread, and conf<BR/>iguration does not allow creation of non-transactional one here at org.springframework.orm.hibernate3.vijhttps://www.blogger.com/profile/05231702469255142716noreply@blogger.comtag:blogger.com,1999:blog-10088978.post-50325546855518832232008-09-29T03:00:00.000-07:002008-09-29T03:00:00.000-07:00That is too large of a topic to be covered in a bl...That is too large of a topic to be covered in a blog comment. You should read the reference documentation at <A HREF="http://static.springframework.org/spring/docs/2.5.x/reference/index.html" REL="nofollow">http://static.springframework.org/spring/docs/2.5.x/reference/index.html</A>, or maybe look at buying a book.<BR/><BR/>You could try posting on the <A HREF="http://forum.springframework.org/" Ray Kruegerhttps://www.blogger.com/profile/06110480752501115735noreply@blogger.comtag:blogger.com,1999:blog-10088978.post-79913391648235869372008-09-28T23:47:00.000-07:002008-09-28T23:47:00.000-07:00Hello,I am new in Spring framework. I want some ex...Hello,<BR/><BR/>I am new in Spring framework. I want some explanation for rolling back from failed insert.<BR/><BR/>In my case, let say that we have 5 items to be saved in persistence. If insert-attempt is failed in the middle, I have to rollback all transactions that have been done. How to make it happen?<BR/><BR/>These are my ApplicationContext-hibernate.xml:<BR/>bean id="msUserDao"<BR/>class="Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-10088978.post-48286222309038300442007-10-23T12:06:00.000-07:002007-10-23T12:06:00.000-07:00I'm posting on your comment at http://forum.hibern...I'm posting on your comment at http://forum.hibernate.org/viewtopic.php?t=980652<BR/><BR/>...and DATETIME isn't supported hibernate type, it's "TIME". That's why you're getting that error.Ray Kruegerhttps://www.blogger.com/profile/06110480752501115735noreply@blogger.comtag:blogger.com,1999:blog-10088978.post-46276677531109497822007-10-23T11:58:00.000-07:002007-10-23T11:58:00.000-07:00I did. I even posted a post on hibernate.org. See ...I did. I even posted a post on hibernate.org. See below. If I use "DATETIME" or "DATE" in the hbm.xml instead of java.util.Date, I get an error stating like that:<BR/><BR/>Could not determine type for: DATETIME, for columns:<BR/><BR/>===POST BELOW====<BR/><BR/>The java.util.Date and the java.sql.Date within the hibernate context is one of the most often asked question.<BR/>It is without a doubt xavzemanhttps://www.blogger.com/profile/04769546224911665973noreply@blogger.comtag:blogger.com,1999:blog-10088978.post-60554157520365841962007-10-23T11:05:00.000-07:002007-10-23T11:05:00.000-07:00You just use java.util.Date instances.In your mapp...You just use java.util.Date instances.<BR/><BR/>In your mappings you tell hibernate if you want that property mapped as a DATE, TIME, or TIMESTAMP.<BR/><BR/>Have a look at the <A HREF="http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-types-basictypes" REL="nofollow">Hibernate Reference</A>Ray Kruegerhttps://www.blogger.com/profile/06110480752501115735noreply@blogger.comtag:blogger.com,1999:blog-10088978.post-8638519340918795192007-10-23T10:19:00.000-07:002007-10-23T10:19:00.000-07:00Hello,Quick little question, with all this abstrac...Hello,<BR/><BR/>Quick little question, with all this abstract layer and with your experience, what do you think is the best way to deal with java.util.Date fields of a model within Hibernate so that the code still works even if you switch database (mySQL,postGresSql...). <BR/><BR/>I read some stuff about it but nothing convincing, I was curious how do you deal with Date fields.xavzemanhttps://www.blogger.com/profile/04769546224911665973noreply@blogger.comtag:blogger.com,1999:blog-10088978.post-72187074796939732672007-10-15T12:28:00.000-07:002007-10-15T12:28:00.000-07:00Actually the HibernateTemplate implements the save...Actually the HibernateTemplate implements the saveOrUpdateAll by iterating over the given collection and calling session.save.<BR/><A HREF="http://springframework.cvs.sourceforge.net/springframework/spring/src/org/springframework/orm/hibernate3/HibernateTemplate.java?revision=1.38&view=markup" REL="nofollow">HibernateTemplate</A><BR/><BR/>There isn't much to optimize in regards to sql inserts andRay Kruegerhttps://www.blogger.com/profile/06110480752501115735noreply@blogger.comtag:blogger.com,1999:blog-10088978.post-73575686921356408082007-10-15T12:12:00.000-07:002007-10-15T12:12:00.000-07:00Without the HibernateTemplate, we are losing some ...Without the HibernateTemplate, we are losing some convenient method like deleteAll or saveOrUpdateAll for Collections.<BR/><BR/>I was wondering a contextual session<BR/>handles collections, if I pass a collection inside the saveOrUpdate method. (After all, a collection is an object). I certainly hope that they identify the type being a collection and optimize the query.<BR/><BR/>Basically, if youxavzemanhttps://www.blogger.com/profile/04769546224911665973noreply@blogger.comtag:blogger.com,1999:blog-10088978.post-13379992564135441362007-10-15T11:43:00.000-07:002007-10-15T11:43:00.000-07:00Glad I could help you in return. And like I said b...Glad I could help you in return. And like I said before, keep up this absolutely useful blog even if i am the only one commenting :)xavzemanhttps://www.blogger.com/profile/04769546224911665973noreply@blogger.comtag:blogger.com,1999:blog-10088978.post-3482005871934991252007-10-15T11:34:00.000-07:002007-10-15T11:34:00.000-07:00That was just really poor wording on my part. I ha...That was just really poor wording on my part. I have corrected it to read "If you are using the Spring LocalSessionFactoryBean to configure your Hibernate SessionFactory, the HibernateTemplate just isn't needed."<BR/><BR/>What you have is absolutely correct.Ray Kruegerhttps://www.blogger.com/profile/06110480752501115735noreply@blogger.comtag:blogger.com,1999:blog-10088978.post-73378593965934884872007-10-15T11:28:00.000-07:002007-10-15T11:28:00.000-07:00Also in a previous post you wrote "If you are usin...Also in a previous post you wrote "If you are using the Spring LocalSessionFactoryBean to configure your Hibernate SessionFactory, it just isn't needed."<BR/><BR/>I understand the reason why if you using Hibernate3 feature of contextuel session like you do, but my question is how do you load your .hbm.xml files now or define your hibernate properties for that matter? How do you associate this xavzemanhttps://www.blogger.com/profile/04769546224911665973noreply@blogger.comtag:blogger.com,1999:blog-10088978.post-46357008806749848142007-10-15T11:10:00.000-07:002007-10-15T11:10:00.000-07:00Copying and pasting from the IDE to the blog only ...Copying and pasting from the IDE to the blog only goes so far :)<BR/><BR/>1) Good Catch. The UserDaoImpl has been updated above to have the proper generics.<BR/><BR/>2) I declare that the I parameter "extends Serializable" because the Hibernate Session API requires Serializable types for it's get() and load() methods.<BR/><BR/>3) The point of my HibernateDao implementations here is that it is notRay Kruegerhttps://www.blogger.com/profile/06110480752501115735noreply@blogger.comtag:blogger.com,1999:blog-10088978.post-44377440241440316512007-10-15T10:55:00.000-07:002007-10-15T10:55:00.000-07:00Hello and thanks for your contribution. I have the...Hello and thanks for your contribution. I have the following follow-up questions for you:<BR/><BR/>1/ isn't it something missing in the concrete class declaration:<BR/> public class UserDaoImpl extends AbstractHibernateDao[User] implements UserDao<BR/><BR/>You changed the abstract class declaration to public abstract class AbstractHibernateDao[E, I extends Serializable]<BR/>from public abstract xavzemanhttps://www.blogger.com/profile/04769546224911665973noreply@blogger.com