You can subscribe to this list here.
2002 |
Jan
(2) |
Feb
(157) |
Mar
(111) |
Apr
(61) |
May
(68) |
Jun
(45) |
Jul
(101) |
Aug
(132) |
Sep
(148) |
Oct
(227) |
Nov
(141) |
Dec
(285) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(518) |
Feb
(462) |
Mar
(390) |
Apr
(488) |
May
(321) |
Jun
(336) |
Jul
(268) |
Aug
(374) |
Sep
(211) |
Oct
(246) |
Nov
(239) |
Dec
(173) |
2004 |
Jan
(110) |
Feb
(131) |
Mar
(85) |
Apr
(120) |
May
(82) |
Jun
(101) |
Jul
(54) |
Aug
(65) |
Sep
(94) |
Oct
(51) |
Nov
(56) |
Dec
(168) |
2005 |
Jan
(146) |
Feb
(98) |
Mar
(75) |
Apr
(118) |
May
(85) |
Jun
(75) |
Jul
(44) |
Aug
(94) |
Sep
(70) |
Oct
(84) |
Nov
(115) |
Dec
(52) |
2006 |
Jan
(113) |
Feb
(83) |
Mar
(217) |
Apr
(158) |
May
(219) |
Jun
(218) |
Jul
(189) |
Aug
(39) |
Sep
(3) |
Oct
(7) |
Nov
(4) |
Dec
(2) |
2007 |
Jan
|
Feb
(2) |
Mar
(7) |
Apr
(3) |
May
(3) |
Jun
(8) |
Jul
(1) |
Aug
(1) |
Sep
|
Oct
(4) |
Nov
(7) |
Dec
|
2008 |
Jan
(1) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
(4) |
Sep
|
Oct
(2) |
Nov
(1) |
Dec
|
2009 |
Jan
(6) |
Feb
|
Mar
(1) |
Apr
(2) |
May
(1) |
Jun
(1) |
Jul
(10) |
Aug
|
Sep
(1) |
Oct
(1) |
Nov
|
Dec
(3) |
2010 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
2012 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Christoph S. <ch...@mc...> - 2002-09-03 10:23:36
|
Hey Jon! I also think that this is a great idea :) What i dont like about your approach is that it always creates a session. > String vSessionId = > ((HttpServletRequest)request).getSession(true).getId(); > Session vSession = (Session)request.getAttribute(vSessionId); Why did you do it this way? Is it not ok to use a string constant as attribute name? I think my approach will be to open the session in the controller, and close it only in the filter, if there is an open session. regards chris ----- Original Message ----- From: "Jon Lipsky" <jon...@xe...> To: "Christoph Sturm" <ch...@mc...>; "Brad Clow" <bra...@wo...>; <hib...@li...> Sent: Tuesday, August 27, 2002 11:46 AM Subject: Re: [Hibernate-devel] mvc & lazy loading > Hi All, > > I use a Filter (a new addition in the 2.3 servlet spec) to open and close my > Hibernate sessions. By doing it this way it doesn't matter if I am using > Velocity or JSP or something else to access Hibernate. As far as the "view" > is concerned the Hibernate session just exists, and only the Filter has to > worry about opening and closing it. > > I was looking at the examples inclued with Hibernate and I was thinking that > maybe an example should be added of using a Filter since it's a good way to > cleanly seperate the creation and closing of the sessions for a web > application. > > Jon... > > PS - Here is a code snippet to get you started if you want to do it this > way: > > package example; > > import cirrus.hibernate.Datastore; > import cirrus.hibernate.Session; > import cirrus.hibernate.SessionFactory; > import cirrus.hibernate.Hibernate; > > import javax.servlet.*; > import javax.servlet.http.HttpServletRequest; > import java.io.IOException; > > public class HibernateFilter implements Filter > { > static org.apache.log4j.Category log = > org.apache.log4j.Category.getInstance(HibernateFilter.class.getName()); > > private Datastore datastore; > private SessionFactory sessions; > > public void doFilter(ServletRequest request, ServletResponse response, > FilterChain chain) throws IOException, ServletException > { > try > { > // Get the http session id from the request, then we will try to get the > Hiberate > // Session from the request. If it doesn't exist, then we will create > it, otherwise > // we will use the one that already exists. > String vSessionId = > ((HttpServletRequest)request).getSession(true).getId(); > Session vSession = (Session)request.getAttribute(vSessionId); > > if (vSession == null) > { > vSession = sessions.openSession(); > request.setAttribute(vSessionId, vSession); > > if (log.isDebugEnabled()) > { > log.debug("Opened hibernate session."); > } > } > } > catch (Exception exc) > { > log.error("Error opening Hibernate session.", exc); > } > > try > { > chain.doFilter(request, response); > } > finally > { > try > { > String vSessionId = ((HttpServletRequest)request).getSession().getId(); > Session vSession = (Session)request.getAttribute(vSessionId); > > // Only try to close the connection if it is open, since it might have > been > // closed somewhere else by mistake. > if (vSession.isOpen()) > { > vSession.close(); > > if (log.isDebugEnabled()) > { > log.debug("Closed hibernate session."); > } > } > } > catch (Exception exc) > { > log.error("Error closing Hibernate session.", exc); > } > } > } > > public void init(FilterConfig aConfig) throws ServletException > { > // Initialize your datastore > datastore = Hibernate.createDatastore(); > > // Initialize your the object -> db mappings > // ... > > // Initialize your session > sessions = datastore.buildSessionFactory(); > } > > public void destroy() > { > > } > } > > > > ----- Original Message ----- > From: "Christoph Sturm" <ch...@mc...> > To: "Brad Clow" <bra...@wo...>; > <hib...@li...> > Sent: Tuesday, August 27, 2002 10:47 AM > Subject: Re: [Hibernate-devel] mvc & lazy loading > > > > Hi Brad! > > > > This subject is an interesting one that I was also thinking of lately. > > I did a test app with maverick (mav.sourceforge.net), and there it was > > really easy. If the controller(=model) implements ModelLifetime, a discard > > function is called when the views are finished and the model is discarded. > > There I closed my session. Other frameworks that just forward to the view > > dont offer this functionality. > > For most of my stuff I use webwork, so I'd like a solution that works > there > > too. I was thinking of closing the session in the finalize method of my > > controller, but then I dont really know when the session will be closed. > > Another possibility would be to to pass the session to velocity, and close > > it in the velocity view servlet after all is rendered. > > > > How did you implement it? > > > > regards > > chris > > ----- Original Message ----- > > From: "Brad Clow" <bra...@wo...> > > To: <hib...@li...> > > Sent: Tuesday, August 27, 2002 12:38 AM > > Subject: [Hibernate-devel] mvc & lazy loading > > > > > > > > > > to date, we have avoided using lazy loading when writing a web app in > > > one of the standard mvc type frameworks (eg. struts, webwork, etc). > > > this is because objects r typically retrieved, placed in the request > > > attributes, session closed and control is then passed to the view (JSP, > > > velocity, etc). if the view attempts to access a lazy loaded collection > > > in one of the objects an exception is thrown as the associated session > > > is closed. > > > > > > what do other people do? > > > > > > yesterday, i spent a few hours writing a very simple webapp framework > > > that uses velocity for the view. it enables the velocity rendering to > > > be done while a session is open. so far this is working quite well for > > > us. > > > > > > comments? > > > > > > brad > > > > > > > _______________________________ > > > > brad clow > > > > chief technical officer > > > > workingmouse > > > > > > > > email: bra...@wo... > > > > web: http://www.workingmouse.com > > > > > > > > > > > > > ------------------------------------------------------- > > > This sf.net email is sponsored by: OSDN - Tired of that same old > > > cell phone? Get a new here for FREE! > > > > > > https://www.inphonic.com/r.asp?r____________________________________________ > > ___ > > > Hibernate-devel mailing list > > > Hib...@li... > > > https://lists.sourceforge.net/lists/listinfo/hibernate-devel > > > > > > > > > > > ------------------------------------------------------- > > This sf.net email is sponsored by: OSDN - Tired of that same old > > cell phone? Get a new here for FREE! > > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > > _______________________________________________ > > Hibernate-devel mailing list > > Hib...@li... > > https://lists.sourceforge.net/lists/listinfo/hibernate-devel > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by: OSDN - Tired of that same old > cell phone? Get a new here for FREE! > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > _______________________________________________ > Hibernate-devel mailing list > Hib...@li... > https://lists.sourceforge.net/lists/listinfo/hibernate-devel > |
From: Jon L. <jon...@xe...> - 2002-09-02 11:40:11
|
Brad, This is exactly what I do... I also have a couple different versions of my filter that handler their own URL filtering using the Apache ORO library. I do this so I can more complex regular expressions for the the URL matching... Jon... ----- Original Message ----- From: "Brad Clow" <bra...@wo...> To: <hib...@li...> Sent: Saturday, August 31, 2002 7:38 AM Subject: Re: [Hibernate-devel] mvc & lazy loading > jon, > > this seems like a pretty neat way of doing it. do u use <filter-mapping> > elements in the web.xml to control which requests it gets applied to - so u > only have a session created for requests that actually need one? > > brad > > > ----- Original Message ----- > From: "Jon Lipsky" <jon...@xe...> > To: "Christoph Sturm" <ch...@mc...>; "Brad Clow" > <bra...@wo...>; <hib...@li...> > Sent: Tuesday, August 27, 2002 7:46 PM > Subject: Re: [Hibernate-devel] mvc & lazy loading > > > > Hi All, > > > > I use a Filter (a new addition in the 2.3 servlet spec) to open and close > my > > Hibernate sessions. By doing it this way it doesn't matter if I am using > > Velocity or JSP or something else to access Hibernate. As far as the > "view" > > is concerned the Hibernate session just exists, and only the Filter has to > > worry about opening and closing it. > > > > I was looking at the examples inclued with Hibernate and I was thinking > that > > maybe an example should be added of using a Filter since it's a good way > to > > cleanly seperate the creation and closing of the sessions for a web > > application. > > > > Jon... > > > > PS - Here is a code snippet to get you started if you want to do it this > > way: > > > > package example; > > > > import cirrus.hibernate.Datastore; > > import cirrus.hibernate.Session; > > import cirrus.hibernate.SessionFactory; > > import cirrus.hibernate.Hibernate; > > > > import javax.servlet.*; > > import javax.servlet.http.HttpServletRequest; > > import java.io.IOException; > > > > public class HibernateFilter implements Filter > > { > > static org.apache.log4j.Category log = > > org.apache.log4j.Category.getInstance(HibernateFilter.class.getName()); > > > > private Datastore datastore; > > private SessionFactory sessions; > > > > public void doFilter(ServletRequest request, ServletResponse response, > > FilterChain chain) throws IOException, ServletException > > { > > try > > { > > // Get the http session id from the request, then we will try to get > the > > Hiberate > > // Session from the request. If it doesn't exist, then we will create > > it, otherwise > > // we will use the one that already exists. > > String vSessionId = > > ((HttpServletRequest)request).getSession(true).getId(); > > Session vSession = (Session)request.getAttribute(vSessionId); > > > > if (vSession == null) > > { > > vSession = sessions.openSession(); > > request.setAttribute(vSessionId, vSession); > > > > if (log.isDebugEnabled()) > > { > > log.debug("Opened hibernate session."); > > } > > } > > } > > catch (Exception exc) > > { > > log.error("Error opening Hibernate session.", exc); > > } > > > > try > > { > > chain.doFilter(request, response); > > } > > finally > > { > > try > > { > > String vSessionId = > ((HttpServletRequest)request).getSession().getId(); > > Session vSession = (Session)request.getAttribute(vSessionId); > > > > // Only try to close the connection if it is open, since it might have > > been > > // closed somewhere else by mistake. > > if (vSession.isOpen()) > > { > > vSession.close(); > > > > if (log.isDebugEnabled()) > > { > > log.debug("Closed hibernate session."); > > } > > } > > } > > catch (Exception exc) > > { > > log.error("Error closing Hibernate session.", exc); > > } > > } > > } > > > > public void init(FilterConfig aConfig) throws ServletException > > { > > // Initialize your datastore > > datastore = Hibernate.createDatastore(); > > > > // Initialize your the object -> db mappings > > // ... > > > > // Initialize your session > > sessions = datastore.buildSessionFactory(); > > } > > > > public void destroy() > > { > > > > } > > } > > > > > > > > ----- Original Message ----- > > From: "Christoph Sturm" <ch...@mc...> > > To: "Brad Clow" <bra...@wo...>; > > <hib...@li...> > > Sent: Tuesday, August 27, 2002 10:47 AM > > Subject: Re: [Hibernate-devel] mvc & lazy loading > > > > > > > Hi Brad! > > > > > > This subject is an interesting one that I was also thinking of lately. > > > I did a test app with maverick (mav.sourceforge.net), and there it was > > > really easy. If the controller(=model) implements ModelLifetime, a > discard > > > function is called when the views are finished and the model is > discarded. > > > There I closed my session. Other frameworks that just forward to the > view > > > dont offer this functionality. > > > For most of my stuff I use webwork, so I'd like a solution that works > > there > > > too. I was thinking of closing the session in the finalize method of my > > > controller, but then I dont really know when the session will be closed. > > > Another possibility would be to to pass the session to velocity, and > close > > > it in the velocity view servlet after all is rendered. > > > > > > How did you implement it? > > > > > > regards > > > chris > > > ----- Original Message ----- > > > From: "Brad Clow" <bra...@wo...> > > > To: <hib...@li...> > > > Sent: Tuesday, August 27, 2002 12:38 AM > > > Subject: [Hibernate-devel] mvc & lazy loading > > > > > > > > > > > > > > to date, we have avoided using lazy loading when writing a web app in > > > > one of the standard mvc type frameworks (eg. struts, webwork, etc). > > > > this is because objects r typically retrieved, placed in the request > > > > attributes, session closed and control is then passed to the view > (JSP, > > > > velocity, etc). if the view attempts to access a lazy loaded > collection > > > > in one of the objects an exception is thrown as the associated session > > > > is closed. > > > > > > > > what do other people do? > > > > > > > > yesterday, i spent a few hours writing a very simple webapp framework > > > > that uses velocity for the view. it enables the velocity rendering to > > > > be done while a session is open. so far this is working quite well > for > > > > us. > > > > > > > > comments? > > > > > > > > brad > > > > > > > > > _______________________________ > > > > > brad clow > > > > > chief technical officer > > > > > workingmouse > > > > > > > > > > email: bra...@wo... > > > > > web: http://www.workingmouse.com > > > > > > > > > > > > > > > > > ------------------------------------------------------- > > > > This sf.net email is sponsored by: OSDN - Tired of that same old > > > > cell phone? Get a new here for FREE! > > > > > > > > > > https://www.inphonic.com/r.asp?r____________________________________________ > > > ___ > > > > Hibernate-devel mailing list > > > > Hib...@li... > > > > https://lists.sourceforge.net/lists/listinfo/hibernate-devel > > > > > > > > > > > > > > > > ------------------------------------------------------- > > > This sf.net email is sponsored by: OSDN - Tired of that same old > > > cell phone? Get a new here for FREE! > > > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > > > _______________________________________________ > > > Hibernate-devel mailing list > > > Hib...@li... > > > https://lists.sourceforge.net/lists/listinfo/hibernate-devel > > > > > > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by: OSDN - Tired of that same old > cell phone? Get a new here for FREE! > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > _______________________________________________ > Hibernate-devel mailing list > Hib...@li... > https://lists.sourceforge.net/lists/listinfo/hibernate-devel > |
From: Brad C. <bra...@wo...> - 2002-09-02 10:38:14
|
hibernate.org.au is available. brad ----- Original Message ----- From: <Gavin_King/Cirrus%CI...@ci...> To: <hib...@li...> Sent: Monday, September 02, 2002 7:07 PM Subject: [Hibernate-devel] Changes > > As of this week, I am no longer working for Cirrus Technologies. This > should have no particular effect upon development of Hibernate, however. I > will be taking a shortish break from work (but not from Hibernate) before I > start looking for a new job. (I've been needing a break and a change for a > while now.) > > At some stage I plan to register a domain name for the project and then > rename packages along Java standard naming conventions. I hadn't done this > previously because all the obvious URLs were unavailable. So if anyone can > think of an available domain that would look better than "cirrus.hibernate" > at the top of their code, suggestions are very welcome :) > > Gavin > > P.S. I will let everyone know my new email address as soon as I can find > something..... (oh, if anyone with a mail server wants to donate a couple > of email addresses to the project, that would be very nice....) > > > > > ------------------------------------------------------- > This sf.net email is sponsored by: OSDN - Tired of that same old > cell phone? Get a new here for FREE! > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > _______________________________________________ > Hibernate-devel mailing list > Hib...@li... > https://lists.sourceforge.net/lists/listinfo/hibernate-devel > |
From: Gavin_King/Cirrus%<CI...@ci...> - 2002-09-02 09:25:10
|
As of this week, I am no longer working for Cirrus Technologies. This should have no particular effect upon development of Hibernate, however. I will be taking a shortish break from work (but not from Hibernate) before I start looking for a new job. (I've been needing a break and a change for a while now.) At some stage I plan to register a domain name for the project and then rename packages along Java standard naming conventions. I hadn't done this previously because all the obvious URLs were unavailable. So if anyone can think of an available domain that would look better than "cirrus.hibernate" at the top of their code, suggestions are very welcome :) Gavin P.S. I will let everyone know my new email address as soon as I can find something..... (oh, if anyone with a mail server wants to donate a couple of email addresses to the project, that would be very nice....) |
From: Anton v. S. <an...@ap...> - 2002-09-02 06:21:11
|
> Would anyone have a use for a new callback interface > > public interface Validatable { > public void validate() throws ValidationException; > } > > that would be called just before saving or updating an object's state? Yes, I would. I used something virtually identical in my home-grown persistence code, before switching to Hibernate, and found it very useful. > (Remember, i'm trying to avoid turning Hibernate into a framework.) I think as long as things like this are small, low-overhead, optional, and useful, they're good. This one seems to qualify... Anton |
From: Gavin_King/Cirrus%<CI...@ci...> - 2002-09-02 04:16:29
|
Would anyone have a use for a new callback interface public interface Validatable { public void validate() throws ValidationException; } that would be called just before saving or updating an object's state? The object wouldn't be allowed to adjust it's own state from inside validate(), just throw an exception if it's invariants were violated. I've wondered about this a few times, but it never passed the bloat test really.... (Remember, i'm trying to avoid turning Hibernate into a framework.) However, if its a thing that would be used its sooo easy to implement. |
From: Gavin_King/Cirrus%<CI...@ci...> - 2002-09-02 00:56:46
|
> Don't you mean the <one-to-one> element? Of course. > Is constrained="false" equivalent to the way it currently works (and I > assume will remain the default)? yes. |
From: Gavin_King/Cirrus%<CI...@ci...> - 2002-09-02 00:55:29
|
You need to specify a discriminator-value for the superclass. The error message is confusing because, by default, Hibernate uses the classname as the discriminator value (and string as the type). |
From: Mark W. <mor...@SM...> - 2002-09-01 23:36:43
|
I seem to be having a problem with the <discriminator> element. It works when the discriminator's type is "string," but not when it is "integer." My mapping file looks like this: <class name="Foo" table="Foo"> <id name="accessionId" column="fooId"> <generator class="assigned" /> </id> <discriminator column="fooType" type="integer" /> <subclass name="FooA" discriminator-value="1"> <property name="a" /> </subclass> <subclass name="FooB" discriminator-value="2"> <property name="b" /> </subclass> <subclass name="FooC" discriminator-value="3"> <property name="c" /> </subclass> </class> And I'm getting the following error: Sep 1, 2002 1:42:39 PM cirrus.hibernate.helpers.XMLHelper parseInputSource INFO: Parsing XML: unknown system id Sep 1, 2002 1:42:39 PM cirrus.hibernate.Environment <clinit> INFO: loaded properties from resource hibernate.properties Sep 1, 2002 1:42:39 PM cirrus.hibernate.Environment <clinit> INFO: echoing all SQL to stdout Sep 1, 2002 1:42:39 PM cirrus.hibernate.Environment <clinit> INFO: using java.io streams to persist binary types Sep 1, 2002 1:42:39 PM cirrus.hibernate.Environment <clinit> INFO: JVM proxy support: true Sep 1, 2002 1:42:39 PM cirrus.hibernate.sql.Dialect <init> INFO: Using dialect: class cirrus.hibernate.sql.OracleDialect Sep 1, 2002 1:42:39 PM cirrus.hibernate.connection.DriverManagerConnectionProvider configure INFO: Hibernate connection pool size: 5 Sep 1, 2002 1:42:39 PM cirrus.hibernate.connection.DriverManagerConnectionProvider configure INFO: JDBC isolation level: 2 Sep 1, 2002 1:42:39 PM cirrus.hibernate.connection.DriverManagerConnectionProvider configure INFO: Using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@localhost:1521:DEV Sep 1, 2002 1:42:39 PM cirrus.hibernate.connection.DriverManagerConnectionProvider configure INFO: Connection properties: {user=woon, password=foo} Sep 1, 2002 1:42:39 PM cirrus.hibernate.ps.PreparedStatementCache <init> INFO: prepared statement cache size: 100 Sep 1, 2002 1:42:39 PM cirrus.hibernate.impl.SessionFactoryImpl <init> INFO: Use outer join fetching: true Sep 1, 2002 1:42:40 PM cirrus.hibernate.impl.SessionFactoryImpl <init> INFO: Use scrollable result sets: true Sep 1, 2002 1:42:40 PM cirrus.hibernate.impl.SessionFactoryImpl <init> INFO: Use JDBC 2 batch updates: true --> cirrus.hibernate.MappingException --> Could not format discriminator value to SQL string: For input string: "Foo" cirrus.hibernate.MappingException: Could not format discriminator value to SQL string: For input str ing: "Foo" at cirrus.hibernate.impl.ClassPersister.<init>(ClassPersister.java:304) at cirrus.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:162) at cirrus.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:92) at cirrus.hibernate.impl.DatastoreImpl.buildSessionFactory(DatastoreImpl.java:60) at test.Hibernate.main(Hibernate.java:32) When I change the discriminator type to a string, however, this will work perfectly fine... This is with the latest CVS build. Anyone else seeing this? Thanks, -Mark |
From: Mark W. <mor...@SM...> - 2002-09-01 20:51:13
|
Gavin_King/Cirrus%CI...@ci... wrote: >This is now implemented as an optional attibute constrained="true|false" on >the <one-to-many> element. > Don't you mean the <one-to-one> element? Is constrained="false" equivalent to the way it currently works (and I assume will remain the default)? Thanks, -Mark |
From: Gavin_King/Cirrus%<CI...@ci...> - 2002-08-31 14:01:37
|
This is now implemented as an optional attibute constrained="true|false" on the <one-to-many> element. |
From: Brad C. <bra...@wo...> - 2002-08-31 05:33:05
|
jon, this seems like a pretty neat way of doing it. do u use <filter-mapping> elements in the web.xml to control which requests it gets applied to - so u only have a session created for requests that actually need one? brad ----- Original Message ----- From: "Jon Lipsky" <jon...@xe...> To: "Christoph Sturm" <ch...@mc...>; "Brad Clow" <bra...@wo...>; <hib...@li...> Sent: Tuesday, August 27, 2002 7:46 PM Subject: Re: [Hibernate-devel] mvc & lazy loading > Hi All, > > I use a Filter (a new addition in the 2.3 servlet spec) to open and close my > Hibernate sessions. By doing it this way it doesn't matter if I am using > Velocity or JSP or something else to access Hibernate. As far as the "view" > is concerned the Hibernate session just exists, and only the Filter has to > worry about opening and closing it. > > I was looking at the examples inclued with Hibernate and I was thinking that > maybe an example should be added of using a Filter since it's a good way to > cleanly seperate the creation and closing of the sessions for a web > application. > > Jon... > > PS - Here is a code snippet to get you started if you want to do it this > way: > > package example; > > import cirrus.hibernate.Datastore; > import cirrus.hibernate.Session; > import cirrus.hibernate.SessionFactory; > import cirrus.hibernate.Hibernate; > > import javax.servlet.*; > import javax.servlet.http.HttpServletRequest; > import java.io.IOException; > > public class HibernateFilter implements Filter > { > static org.apache.log4j.Category log = > org.apache.log4j.Category.getInstance(HibernateFilter.class.getName()); > > private Datastore datastore; > private SessionFactory sessions; > > public void doFilter(ServletRequest request, ServletResponse response, > FilterChain chain) throws IOException, ServletException > { > try > { > // Get the http session id from the request, then we will try to get the > Hiberate > // Session from the request. If it doesn't exist, then we will create > it, otherwise > // we will use the one that already exists. > String vSessionId = > ((HttpServletRequest)request).getSession(true).getId(); > Session vSession = (Session)request.getAttribute(vSessionId); > > if (vSession == null) > { > vSession = sessions.openSession(); > request.setAttribute(vSessionId, vSession); > > if (log.isDebugEnabled()) > { > log.debug("Opened hibernate session."); > } > } > } > catch (Exception exc) > { > log.error("Error opening Hibernate session.", exc); > } > > try > { > chain.doFilter(request, response); > } > finally > { > try > { > String vSessionId = ((HttpServletRequest)request).getSession().getId(); > Session vSession = (Session)request.getAttribute(vSessionId); > > // Only try to close the connection if it is open, since it might have > been > // closed somewhere else by mistake. > if (vSession.isOpen()) > { > vSession.close(); > > if (log.isDebugEnabled()) > { > log.debug("Closed hibernate session."); > } > } > } > catch (Exception exc) > { > log.error("Error closing Hibernate session.", exc); > } > } > } > > public void init(FilterConfig aConfig) throws ServletException > { > // Initialize your datastore > datastore = Hibernate.createDatastore(); > > // Initialize your the object -> db mappings > // ... > > // Initialize your session > sessions = datastore.buildSessionFactory(); > } > > public void destroy() > { > > } > } > > > > ----- Original Message ----- > From: "Christoph Sturm" <ch...@mc...> > To: "Brad Clow" <bra...@wo...>; > <hib...@li...> > Sent: Tuesday, August 27, 2002 10:47 AM > Subject: Re: [Hibernate-devel] mvc & lazy loading > > > > Hi Brad! > > > > This subject is an interesting one that I was also thinking of lately. > > I did a test app with maverick (mav.sourceforge.net), and there it was > > really easy. If the controller(=model) implements ModelLifetime, a discard > > function is called when the views are finished and the model is discarded. > > There I closed my session. Other frameworks that just forward to the view > > dont offer this functionality. > > For most of my stuff I use webwork, so I'd like a solution that works > there > > too. I was thinking of closing the session in the finalize method of my > > controller, but then I dont really know when the session will be closed. > > Another possibility would be to to pass the session to velocity, and close > > it in the velocity view servlet after all is rendered. > > > > How did you implement it? > > > > regards > > chris > > ----- Original Message ----- > > From: "Brad Clow" <bra...@wo...> > > To: <hib...@li...> > > Sent: Tuesday, August 27, 2002 12:38 AM > > Subject: [Hibernate-devel] mvc & lazy loading > > > > > > > > > > to date, we have avoided using lazy loading when writing a web app in > > > one of the standard mvc type frameworks (eg. struts, webwork, etc). > > > this is because objects r typically retrieved, placed in the request > > > attributes, session closed and control is then passed to the view (JSP, > > > velocity, etc). if the view attempts to access a lazy loaded collection > > > in one of the objects an exception is thrown as the associated session > > > is closed. > > > > > > what do other people do? > > > > > > yesterday, i spent a few hours writing a very simple webapp framework > > > that uses velocity for the view. it enables the velocity rendering to > > > be done while a session is open. so far this is working quite well for > > > us. > > > > > > comments? > > > > > > brad > > > > > > > _______________________________ > > > > brad clow > > > > chief technical officer > > > > workingmouse > > > > > > > > email: bra...@wo... > > > > web: http://www.workingmouse.com > > > > > > > > > > > > > ------------------------------------------------------- > > > This sf.net email is sponsored by: OSDN - Tired of that same old > > > cell phone? Get a new here for FREE! > > > > > > https://www.inphonic.com/r.asp?r____________________________________________ > > ___ > > > Hibernate-devel mailing list > > > Hib...@li... > > > https://lists.sourceforge.net/lists/listinfo/hibernate-devel > > > > > > > > > > > ------------------------------------------------------- > > This sf.net email is sponsored by: OSDN - Tired of that same old > > cell phone? Get a new here for FREE! > > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > > _______________________________________________ > > Hibernate-devel mailing list > > Hib...@li... > > https://lists.sourceforge.net/lists/listinfo/hibernate-devel > > > > |
From: Brad C. <bra...@wo...> - 2002-08-31 05:13:56
|
originally i wondered whether this would work as the struts action servlet does a RequestDispatcher.forward to pass control to the resource specified by the ActionForward resulting from an Action. however, i did a quick little test, and i think your solution would work. ideally though, u would only want a session created if the processing of the request used hibernate. brad ----- Original Message ----- From: "Colin Evans" <ce...@mo...> To: <hib...@li...>; <bra...@wo...> Sent: Wednesday, August 28, 2002 6:59 AM Subject: Re: mvc & lazy loading > Hi Brad, > > I haven't tried this yet, but if I wanted to use lazy loading with Struts, I > would probably override ActionServlet and do something like this, and have > my DAO layer pull the session from the request context as needed: > > ---- > /** > * Hibernate Action Servlet > */ > public class HibernateActionServlet > extends ActionServlet > { > public void service(HttpServletRequest request, > HttpServletResponse response) > { > Session session = null; > try > { > session = factory.openSession(); > request.setAttribute("session", session); > super.service(request, response); > } > finally > { > if(session != null) session.close(); > } > } > } > ---- > > Do other frameworks allow the controller servlet to be overridden? This > probably is a fairly straightforward way to get lazy loading working. > > -Colin > > -- > Colin Evans > Mobilesys > www.mobilesys.com > |
From: Gavin_King/Cirrus%<CI...@ci...> - 2002-08-31 03:44:28
|
>That sounds perfect. Any chance of this happening in the near future? >I'm sort of at a dead end at the moment because of this. Yeah, its easy enough to implement. I'll have a look at it today if you like. >I was hoping to use the Lifecycle interface to get around this problem, >but it looks like you only get callbacks before the event and not after >the event. Have you considered extending Lifecycle to support this? Its very difficult to strike a balance with the Lifecycle interface. Theres all kind of events that could be useful but, on the other hand, we want the interface to be as simple as possible and we don't want to let assumptions about the internal dynamics of the session implementation "seep" into the API. The other thing is that its very difficult to change callback interfaces (you can deprecate methods but never add new ones). So Hibernate tries to stay as far away as possible from these kind of frameworky solutions to problems. I think its better to address this particular issue as proposed.... Of course, I am very open to other people's opinions on this. |
From: Mark W. <mor...@SM...> - 2002-08-31 02:06:15
|
Gavin_King/Cirrus%CI...@ci... wrote: >So we should add something like: > > <one-to-one name="child" constrained="outward"/> > >and a matching > > <one-to-one name="parent" constrained="inward"/> > >or something like that.... > > That sounds perfect. Any chance of this happening in the near future? I'm sort of at a dead end at the moment because of this. I was hoping to use the Lifecycle interface to get around this problem, but it looks like you only get callbacks before the event and not after the event. Have you considered extending Lifecycle to support this? Thanks, -Mark |
From: Gavin_King/Cirrus%<CI...@ci...> - 2002-08-31 01:43:26
|
Yeah, this is interesting. This problem is specific to one-to-one associations. Firstly, yes there is a way, simply call save() for the parent before calling save() for the children. Hibernate *always* inserts rows in the same order the objects were saved. However, there is a problem for saves cascaded through cascade="all". The problem is that one-to-one associations are by nature bidirectional so in the absence of any other metadata we wouldn't know whether the foreign key was from "parent" to "child" or vice-versa. Currently Hibernate just treats one-to-one associations like many-to-one (ie. assumes the foreign key runs from "parent" to "child" and so inserts the child row first). (Saves cascaded via Lifecycle callbacks could also suffer the same problem, but theres not much we can do about that.) In the case of many-to-one relationships, there is another trick used to ensure no constraint violations occur, even in the case of circular foreign key references. Hibernate is able to insert a null into the foreign key column and then update it later. Unfortunately we can't use this technique with one-to-ones because the foreign key constrains the primary keys. So the general solution to this problem must involve adding an attribute to the <one-to-one> element to tell Hibernate which direction the foreign key constraint points and hence whether the association should be cascaded before or after the parent is saved. (This would also let as create the foreign key from the SchemaExport tool.) So we should add something like: <one-to-one name="child" constrained="outward"/> and a matching <one-to-one name="parent" constrained="inward"/> or something like that.... |
From: Mark W. <mor...@SM...> - 2002-08-30 21:37:34
|
Yaron Zakai wrote: >Hi, > > On an earlier post, Gavin proposed to follow my proposal and make an API >modification > - there were no objections for that. >I would like to understand what is the next step. If there is an issue with >implementing >the change, I hereby volunteer to implement it. Assuming I will make the >modification soon, is there a chance to get it into 1.1? > Gavin already got to it! Check out the latest beta (although I think he did it in b10). -Mark |
From: Yaron Z. <ya...@id...> - 2002-08-30 21:21:35
|
Hi, On an earlier post, Gavin proposed to follow my proposal and make an API modification - there were no objections for that. I would like to understand what is the next step. If there is an issue with implementing the change, I hereby volunteer to implement it. Assuming I will make the modification soon, is there a chance to get it into 1.1? Thanks, Yaron. ---------------------------------------------------------------------------- ----------------------------- Quote from Gavin http://sourceforge.net/forum/forum.php?thread_id=722838&forum_id=128638 Yaron Zakai makes a suggestion I quite like. I've seen that new users often have trouble realizing they need to use insert() instead of save() when they want to use application-assigned ids. People seem to expect that the "assigned" id generator will just use the existing id of an object when you call save(). Secondly, some people would like insert() to cascade to insert(). Whereas other times insert() to save() is appropriate. So I would like to deprecate the following methods: Session.insert(Object) Session.insert(Object, Serializable) and add the following method Session.save(Object, Serializable) (which does exactly what Session.insert(Object, Serializable) used to do.) Then we would deprecate the IDGenerator interface and replace it with: public interface IdentifierGenerator { public Serializable generate(SessionImplementor session, Object entity) throws ..... ; } |
From: Mark W. <mor...@al...> - 2002-08-30 09:01:16
|
Hi all... Is there a way for Hibernate to persist the parent before any children? I've an object Foo which has a child Bar, and the mapping looks like this: <class name="Foo"> <id name="id"> <generator class="assigned" /> </id> <one-to-one name="bar" class="Bar" /> </class> <class name="Bar"> <id name="id"> <generator class="assigned" /> </id> </class> I'm having problems because Bar's id must be a foreign key into Foo. Because Bar gets created before Foo, I get a constraint violation. Is there a way around this? I suspect that this would also be necessary to support normalized mappings. Thanks, -Mark |
From: Colin E. <ce...@mo...> - 2002-08-27 20:59:55
|
Hi Brad, I haven't tried this yet, but if I wanted to use lazy loading with Struts, I would probably override ActionServlet and do something like this, and have my DAO layer pull the session from the request context as needed: ---- /** * Hibernate Action Servlet */ public class HibernateActionServlet extends ActionServlet { public void service(HttpServletRequest request, HttpServletResponse response) { Session session = null; try { session = factory.openSession(); request.setAttribute("session", session); super.service(request, response); } finally { if(session != null) session.close(); } } } ---- Do other frameworks allow the controller servlet to be overridden? This probably is a fairly straightforward way to get lazy loading working. -Colin -- Colin Evans Mobilesys www.mobilesys.com |
From: Lenny S. <lr...@fa...> - 2002-08-27 14:12:51
|
From: Lenny S. <lr...@fa...> - 2002-08-27 14:12:51
|
From: Gavin_King/Cirrus%<CI...@ci...> - 2002-08-27 12:55:46
|
Depends upon the database. Check the source of the cirrus.hibernate.sql package for the mapping for your particular dialect. Please post these kind of questions in the user forum, rather than the development mailing list. Oh, and the bugfix you requested (update() for classes with no property columns) is now in CVS.... peace |
From: Mark W. <mor...@SM...> - 2002-08-27 12:35:49
|
Hi all... Can anyone tell me what Hibernate expects the db column type to be if I specify type="boolean" in the mapping file? Thanks, -Mark |
From: Jon L. <jon...@xe...> - 2002-08-27 09:46:22
|
Hi All, I use a Filter (a new addition in the 2.3 servlet spec) to open and close my Hibernate sessions. By doing it this way it doesn't matter if I am using Velocity or JSP or something else to access Hibernate. As far as the "view" is concerned the Hibernate session just exists, and only the Filter has to worry about opening and closing it. I was looking at the examples inclued with Hibernate and I was thinking that maybe an example should be added of using a Filter since it's a good way to cleanly seperate the creation and closing of the sessions for a web application. Jon... PS - Here is a code snippet to get you started if you want to do it this way: package example; import cirrus.hibernate.Datastore; import cirrus.hibernate.Session; import cirrus.hibernate.SessionFactory; import cirrus.hibernate.Hibernate; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import java.io.IOException; public class HibernateFilter implements Filter { static org.apache.log4j.Category log = org.apache.log4j.Category.getInstance(HibernateFilter.class.getName()); private Datastore datastore; private SessionFactory sessions; public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try { // Get the http session id from the request, then we will try to get the Hiberate // Session from the request. If it doesn't exist, then we will create it, otherwise // we will use the one that already exists. String vSessionId = ((HttpServletRequest)request).getSession(true).getId(); Session vSession = (Session)request.getAttribute(vSessionId); if (vSession == null) { vSession = sessions.openSession(); request.setAttribute(vSessionId, vSession); if (log.isDebugEnabled()) { log.debug("Opened hibernate session."); } } } catch (Exception exc) { log.error("Error opening Hibernate session.", exc); } try { chain.doFilter(request, response); } finally { try { String vSessionId = ((HttpServletRequest)request).getSession().getId(); Session vSession = (Session)request.getAttribute(vSessionId); // Only try to close the connection if it is open, since it might have been // closed somewhere else by mistake. if (vSession.isOpen()) { vSession.close(); if (log.isDebugEnabled()) { log.debug("Closed hibernate session."); } } } catch (Exception exc) { log.error("Error closing Hibernate session.", exc); } } } public void init(FilterConfig aConfig) throws ServletException { // Initialize your datastore datastore = Hibernate.createDatastore(); // Initialize your the object -> db mappings // ... // Initialize your session sessions = datastore.buildSessionFactory(); } public void destroy() { } } ----- Original Message ----- From: "Christoph Sturm" <ch...@mc...> To: "Brad Clow" <bra...@wo...>; <hib...@li...> Sent: Tuesday, August 27, 2002 10:47 AM Subject: Re: [Hibernate-devel] mvc & lazy loading > Hi Brad! > > This subject is an interesting one that I was also thinking of lately. > I did a test app with maverick (mav.sourceforge.net), and there it was > really easy. If the controller(=model) implements ModelLifetime, a discard > function is called when the views are finished and the model is discarded. > There I closed my session. Other frameworks that just forward to the view > dont offer this functionality. > For most of my stuff I use webwork, so I'd like a solution that works there > too. I was thinking of closing the session in the finalize method of my > controller, but then I dont really know when the session will be closed. > Another possibility would be to to pass the session to velocity, and close > it in the velocity view servlet after all is rendered. > > How did you implement it? > > regards > chris > ----- Original Message ----- > From: "Brad Clow" <bra...@wo...> > To: <hib...@li...> > Sent: Tuesday, August 27, 2002 12:38 AM > Subject: [Hibernate-devel] mvc & lazy loading > > > > > > to date, we have avoided using lazy loading when writing a web app in > > one of the standard mvc type frameworks (eg. struts, webwork, etc). > > this is because objects r typically retrieved, placed in the request > > attributes, session closed and control is then passed to the view (JSP, > > velocity, etc). if the view attempts to access a lazy loaded collection > > in one of the objects an exception is thrown as the associated session > > is closed. > > > > what do other people do? > > > > yesterday, i spent a few hours writing a very simple webapp framework > > that uses velocity for the view. it enables the velocity rendering to > > be done while a session is open. so far this is working quite well for > > us. > > > > comments? > > > > brad > > > > > _______________________________ > > > brad clow > > > chief technical officer > > > workingmouse > > > > > > email: bra...@wo... > > > web: http://www.workingmouse.com > > > > > > > > > ------------------------------------------------------- > > This sf.net email is sponsored by: OSDN - Tired of that same old > > cell phone? Get a new here for FREE! > > > https://www.inphonic.com/r.asp?r____________________________________________ > ___ > > Hibernate-devel mailing list > > Hib...@li... > > https://lists.sourceforge.net/lists/listinfo/hibernate-devel > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by: OSDN - Tired of that same old > cell phone? Get a new here for FREE! > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > _______________________________________________ > Hibernate-devel mailing list > Hib...@li... > https://lists.sourceforge.net/lists/listinfo/hibernate-devel > |