RE: Hibernate plugin

2003-11-25 Thread David Friedman
I have a Hibernate JNDI tidbit to impart.

Accoring to the Hibernate forums, there are 2 scopes for JNDI in Tomcat.
One seems to be making a context internally visible to apps within that
Tomcat instance only.  The other, or so it was described to me, allows
external lookups.  So much for self-learning (er.. hacking around with)
JNDI.

I was told that if you want JNDI on that second type, you'll need to set the
properties:

(in a hibernate.properties file)
hibernate.jndi.url=SOMETHING
hibernate.jndi.class=SOMETHING_ELSE

(Or if used in a hibernate.cfg.xml file:
SOMETHING
SOMETHING_ELSE

Regards,
David

P.S. Anyone have a good, simple explantion of the supposed 2 JNDI scopes for
me?

-Original Message-
From: Mark Lowe [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 25, 2003 11:21 AM
To: Struts Users Mailing List
Subject: Re: Hibernate plugin


Opps!! an inconsistency.


SessionFactory sf = (SessionFactory)
ctx.lookup("foo:/hibernate/SessionFactory");

On 25 Nov 2003, at 16:07, Mark Lowe wrote:

> Hi Gopal
>
> David cleared this one up for me off the list (Big thanks), I assume
> you've the same problem with folks trying to create publishing niches
> by making stuff confusing. If you get time before be then someone
> should post this on the hibernate site below the where the class is to
> stop folks getting all messed up over this.
>
> The plugin on the hibernate site works just fine, the important thing
> is to forget the messing with server and web.xml.
>
> 
>  "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
>   "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd";>
>
> 
>
> 
>
> 
>  name="dialect">net.sf.hibernate.dialect.MySQLDialect
> brian
> arses
>  name="connection.url">jdbc:mysql://localhost:3306/mydata
>  name="connection.driver_class">com.mysql.jdbc.Driver
> true
> true
>  name="transaction.factory_class">net.sf.hibernate.transaction.JDBCTrans
> actionFactory
> 1
> true
>
> 
> 
>
> 
>
> 
>
> and in struts config..
>
>   
>   
>   
>
> ..
>
> Context ctx = new InitialContext();
> SessionFactory sf = (SessionFactory)
> ctx.lookup("mnye:/hibernate/SessionFactory");
> hibSession = sf.openSession();
>
> Query query = hibSession.createQuery("from com.sparrow.om.Arse");
> Iterator it = query.iterate();
>
> while(it.hasNext()) {
>   Arse arse = (Arse) it.next();
>   arseList.add(arse);
> }
>
> request.setAttribute("arses", arseList.toArray());
>
> ..
>
>
> Cheers Mark
>
>
> On 24 Nov 2003, at 15:11, Gopal Venkata Achi wrote:
>
>> Hi David,
>> We are in the process of choosing the Hibernate for one of my
>> applications.  Can you let me know, how does it help us, and under
>> what circumstances, we use this tool.  I have gone thru the Hibernate
>> docs, but have not got the clear idea.
>> Please help me in this regard.
>> Regards,
>> gopal
>>
>>  -Original Message-
>>  From: David Friedman [mailto:[EMAIL PROTECTED]
>>  Sent: Mon 11/24/2003 12:02 AM
>>  To: Struts Users Mailing List
>>  Cc:
>>  Subject: RE: Hibernate plugin
>>
>>
>>
>>  Mark,
>>
>>  I have a simpler approach for Hibernate (v2.0.3 or v2.1 under Struts
>> v1.0 or
>>  v1.1)
>>
>>  1. Start with the Hibernate example Struts PlugIn code and
>> struts-config.xml
>>  configuration text at:
>>  http://www.hibernate.org/105.html
>>
>>  2. Do NOT put any context entries in server.xml or web.xml!
>>
>>  3. Choose any name OTHER than the example
>> "java:comp/env/jdbc/mn-test".  Any
>>  name under "java:/comp" in Tomcat is read-only and cannot be used.  I
>>  selected one using my initial and some related hibernate words
>>  "dgf:/hibernate/SessionFactory".  Put that in your hibernate.cfg.xml
>> file as
>>  the 'name="..."' parameter of the session-factory tag, along the
>> lines of
>>  this example:
>>
>>  
>>  
>>  
>>  
>>  
>>
>>  If you use a hibernate.properties file, what you need is described
>> here:
>>  http://www.hibernate.org/hib_docs/api/net/sf/hibernate/cfg/
>> Environment.html
>>
>>  Since I use hiberna

Re: Hibernate plugin

2003-11-25 Thread Mark Lowe
Opps!! an inconsistency.

SessionFactory sf = (SessionFactory)  
ctx.lookup("foo:/hibernate/SessionFactory");

On 25 Nov 2003, at 16:07, Mark Lowe wrote:

Hi Gopal

David cleared this one up for me off the list (Big thanks), I assume  
you've the same problem with folks trying to create publishing niches  
by making stuff confusing. If you get time before be then someone  
should post this on the hibernate site below the where the class is to  
stop folks getting all messed up over this.

The plugin on the hibernate site works just fine, the important thing  
is to forget the messing with server and web.xml.


http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd";>



   

net.sf.hibernate.dialect.MySQLDialect
brian
arses
jdbc:mysql://localhost:3306/mydata
com.mysql.jdbc.Driver
true
true
net.sf.hibernate.transaction.JDBCTrans 
actionFactory
1
true
		







and in struts config..




..

Context ctx = new InitialContext();
SessionFactory sf = (SessionFactory)  
ctx.lookup("mnye:/hibernate/SessionFactory");
hibSession = sf.openSession();

Query query = hibSession.createQuery("from com.sparrow.om.Arse");
Iterator it = query.iterate();

while(it.hasNext()) {
Arse arse = (Arse) it.next();
arseList.add(arse);
}

request.setAttribute("arses", arseList.toArray());
..

Cheers Mark

On 24 Nov 2003, at 15:11, Gopal Venkata Achi wrote:

Hi David,
We are in the process of choosing the Hibernate for one of my  
applications.  Can you let me know, how does it help us, and under  
what circumstances, we use this tool.  I have gone thru the Hibernate  
docs, but have not got the clear idea.
Please help me in this regard.
Regards,
gopal

-Original Message-
From: David Friedman [mailto:[EMAIL PROTECTED]
Sent: Mon 11/24/2003 12:02 AM
To: Struts Users Mailing List
Cc:
Subject: RE: Hibernate plugin


	Mark,
	
	I have a simpler approach for Hibernate (v2.0.3 or v2.1 under Struts  
v1.0 or
	v1.1)
	
	1. Start with the Hibernate example Struts PlugIn code and  
struts-config.xml
	configuration text at:
	http://www.hibernate.org/105.html
	
	2. Do NOT put any context entries in server.xml or web.xml!
	
	3. Choose any name OTHER than the example  
"java:comp/env/jdbc/mn-test".  Any
	name under "java:/comp" in Tomcat is read-only and cannot be used.  I
	selected one using my initial and some related hibernate words
	"dgf:/hibernate/SessionFactory".  Put that in your hibernate.cfg.xml  
file as
	the 'name="..."' parameter of the session-factory tag, along the  
lines of
	this example:
	
	
	
	
	
	
	
	If you use a hibernate.properties file, what you need is described  
here:
	http://www.hibernate.org/hib_docs/api/net/sf/hibernate/cfg/ 
Environment.html
	
	Since I use hibernate.cfg.xml instead of hibernate.properties, I'm  
guessing
	you'll need something like this in your hibernate.properties file:
	hibernate.jndi.url dgf:/hibernate
	hibernate.jndi.class javax.naming.Context
	hibernate.session_factory_name SessionFactory
	
	4. Hibernate creates the non-existent JNDI context for me on webapp  
start
	and puts the session-factory in it.  My facade class opens the  
session this
	way:
	
	Content ctx = new InitialContext();
	SessionFactory sf = (SessionFactory) ctx.lookup(jndiLocation);
	Session session = sf.openSession();
	
	That's all I do.  Oh, I'm using hibernate 2.1beta6 now for my facade  
because
	it allows me to use named parameters in queries and hide the  
hibernate types
	more easily.  (sorry, I think I read too much into Ted Husted's  
Struts in
	Action book, I'm trying to facade EVERYTHING! LOL).
	
	Feel free to email me off-list if you need futher help.
	
	Regards,
	David
	
	
	-Original Message-
	From: Mark Lowe [mailto:[EMAIL PROTECTED]
	Sent: Monday, November 24, 2003 12:32 AM
	To: Struts Users Mailing List
	Subject: Hibernate plugin
	
	
	After spending all night pissing around with various hibernate  
plugins
	to provide a datasource to use with hibernate?
	
	My JNDI datasource reports being okay in my container log,
	
	
	reloadable="true"  
crossContext="true">
	
	prefix="mn-test"  
suffix=".log" timestamp="true" />
	
	
	type="javax.sql.DataSource" />
	
	..
	
	then in my hibernate.cfg.xml
	
	
	java:comp/env/jdbc/mn-test
	
	
	...
	
	Every-time i try and get the datasource from the servlet context I  
get
	a null poin

Re: Hibernate plugin

2003-11-25 Thread Mark Lowe
Hi Gopal

David cleared this one up for me off the list (Big thanks), I assume  
you've the same problem with folks trying to create publishing niches  
by making stuff confusing. If you get time before be then someone  
should post this on the hibernate site below the where the class is to  
stop folks getting all messed up over this.

The plugin on the hibernate site works just fine, the important thing  
is to forget the messing with server and web.xml.


http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd";>



   

net.sf.hibernate.dialect.MySQLDialect
brian
arses
jdbc:mysql://localhost:3306/mydata
com.mysql.jdbc.Driver
true
true
net.sf.hibernate.transaction.JDBCTransa 
ctionFactory
1
true
		







and in struts config..




..

Context ctx = new InitialContext();
SessionFactory sf = (SessionFactory)  
ctx.lookup("mnye:/hibernate/SessionFactory");
hibSession = sf.openSession();

Query query = hibSession.createQuery("from com.sparrow.om.Arse");
Iterator it = query.iterate();

while(it.hasNext()) {
Arse arse = (Arse) it.next();
arseList.add(arse);
}

request.setAttribute("arses", arseList.toArray());
..

Cheers Mark

On 24 Nov 2003, at 15:11, Gopal Venkata Achi wrote:

Hi David,
We are in the process of choosing the Hibernate for one of my  
applications.  Can you let me know, how does it help us, and under  
what circumstances, we use this tool.  I have gone thru the Hibernate  
docs, but have not got the clear idea.
Please help me in this regard.
Regards,
gopal

-Original Message-
From: David Friedman [mailto:[EMAIL PROTECTED]
Sent: Mon 11/24/2003 12:02 AM
To: Struts Users Mailing List
    Cc:
Subject: RE: Hibernate plugin


	Mark,
	
	I have a simpler approach for Hibernate (v2.0.3 or v2.1 under Struts  
v1.0 or
	v1.1)
	
	1. Start with the Hibernate example Struts PlugIn code and  
struts-config.xml
	configuration text at:
	http://www.hibernate.org/105.html
	
	2. Do NOT put any context entries in server.xml or web.xml!
	
	3. Choose any name OTHER than the example  
"java:comp/env/jdbc/mn-test".  Any
	name under "java:/comp" in Tomcat is read-only and cannot be used.  I
	selected one using my initial and some related hibernate words
	"dgf:/hibernate/SessionFactory".  Put that in your hibernate.cfg.xml  
file as
	the 'name="..."' parameter of the session-factory tag, along the  
lines of
	this example:
	
	
	
	
	
	
	
	If you use a hibernate.properties file, what you need is described  
here:
	http://www.hibernate.org/hib_docs/api/net/sf/hibernate/cfg/ 
Environment.html
	
	Since I use hibernate.cfg.xml instead of hibernate.properties, I'm  
guessing
	you'll need something like this in your hibernate.properties file:
	hibernate.jndi.url dgf:/hibernate
	hibernate.jndi.class javax.naming.Context
	hibernate.session_factory_name SessionFactory
	
	4. Hibernate creates the non-existent JNDI context for me on webapp  
start
	and puts the session-factory in it.  My facade class opens the  
session this
	way:
	
	Content ctx = new InitialContext();
	SessionFactory sf = (SessionFactory) ctx.lookup(jndiLocation);
	Session session = sf.openSession();
	
	That's all I do.  Oh, I'm using hibernate 2.1beta6 now for my facade  
because
	it allows me to use named parameters in queries and hide the  
hibernate types
	more easily.  (sorry, I think I read too much into Ted Husted's  
Struts in
	Action book, I'm trying to facade EVERYTHING! LOL).
	
	Feel free to email me off-list if you need futher help.
	
	Regards,
	David
	
	
	-Original Message-
	From: Mark Lowe [mailto:[EMAIL PROTECTED]
	Sent: Monday, November 24, 2003 12:32 AM
	To: Struts Users Mailing List
	Subject: Hibernate plugin
	
	
	After spending all night pissing around with various hibernate plugins
	to provide a datasource to use with hibernate?
	
	My JNDI datasource reports being okay in my container log,
	
	
	reloadable="true" crossContext="true">
	
	prefix="mn-test"  
suffix=".log" timestamp="true" />
	
	
	type="javax.sql.DataSource" />
	
	..
	
	then in my hibernate.cfg.xml
	
	
	java:comp/env/jdbc/mn-test
	
	
	...
	
	Every-time i try and get the datasource from the servlet context I get
	a null pointer exception.. While this of course is a life changing
	experience for me, i novelty is waring thin. If anyone has is working
	in reality , then any input would be greatly apprec

RE: Hibernate plugin

2003-11-24 Thread David Friedman
Gopal,

I like hibernate for a few simple things:

1. Auto-population of objects.  I hate copying SQL columns or adding a second step by 
calling beanutils.copyproperties.

2. Describe your object and hibernate can:

A) Auto-generate my java object code (hbm2java)
B) Auto-update my database tables if my fields change type or new ones are added 
(SchemaUpdate)
C( Describe on auto-code-generation what interfaces or 'extends' to use for that 
class. (*.hbm.xml 'meta' attributes).
D) Auto-load any subsets or sub-tables it refers to.  Got an author who has one or 
more 'works'?  You could have it load that data automatically.  Got a login/pw/id in 
one table but want it to load the customer data in another table automatically?  Link 
them with a type of component so when you ask for the user with login 'fred', it 
populates the object from both tables.

3. Time-savers:

a) Plug-ins for caches (EhCache, OSCache, JCS, etc.)
b) It's own query language can auto-translate to various database brands/types so you 
can have multiple database products and your query will be automatically translated 
and use the right userid/password/database/table for what you're looking for (DB2, 
Firebird, FrontBase, HSQLD, Informix, Ingres, Interbase, Mckoi, MySQL, Oracle, 
Pointbase, PostgreSQL, Postgress, SAPDB, Sybase, etc.), which it calls Dialects.
c) Auto-logins to each database (no need for DataSource configurations or anything 
like that)
d) Can automatically install each data souce as a JNDI name (I use this in 
Tomcat+Struts+Hibernate) so I can use it without passing the session back and forth 
(good for hiding your database access object.

4. The mapping file(s) describes objects and relationships so it can auto-log any 
one-to-one, one-to-many, many-to-one, many-to-many, bidirectional, and even 
tridirectional relationships in the object.  I can make it auto-load that information 
if I want as well.

This are my favorite reasons, thought I've never used 3.b (yet). :) I'm sure there are 
more reasons so check out http://www.hibernate.org and it's forum 
http://forum.hibernate.org, which answers a load of questions.

Did I mention that I think Hibernate was just taken over by JBoss so they have at 
least one dedicated programmer (full-time, 9-5 daily).  That might comfort you knowing 
there is one person who's probably on their message boards 9-5 every day. :)

Feel free to off-list me if you have more questions.  I'm probably driving everyone 
CRAZY with my incessant posting the last day or two.

Regards,
David

-Original Message-
From: Gopal Venkata Achi [mailto:[EMAIL PROTECTED]
Sent: Monday, November 24, 2003 10:12 AM
To: Struts Users Mailing List
Subject: RE: Hibernate plugin


Hi David,
We are in the process of choosing the Hibernate for one of my applications.  Can you 
let me know, how does it help us, and under what circumstances, we use this tool.  I 
have gone thru the Hibernate docs, but have not got the clear idea.
Please help me in this regard.
Regards,
gopal

-Original Message- 
From: David Friedman [mailto:[EMAIL PROTECTED] 
Sent: Mon 11/24/2003 12:02 AM 
    To: Struts Users Mailing List 
Cc: 
Subject: RE: Hibernate plugin



Mark,

I have a simpler approach for Hibernate (v2.0.3 or v2.1 under Struts v1.0 or
v1.1)

1. Start with the Hibernate example Struts PlugIn code and struts-config.xml
configuration text at:
http://www.hibernate.org/105.html

2. Do NOT put any context entries in server.xml or web.xml!

3. Choose any name OTHER than the example "java:comp/env/jdbc/mn-test".  Any
name under "java:/comp" in Tomcat is read-only and cannot be used.  I
selected one using my initial and some related hibernate words
"dgf:/hibernate/SessionFactory".  Put that in your hibernate.cfg.xml file as
the 'name="..."' parameter of the session-factory tag, along the lines of
this example:







If you use a hibernate.properties file, what you need is described here:
http://www.hibernate.org/hib_docs/api/net/sf/hibernate/cfg/Environment.html

Since I use hibernate.cfg.xml instead of hibernate.properties, I'm guessing
you'll need something like this in your hibernate.properties file:
hibernate.jndi.url dgf:/hibernate
hibernate.jndi.class javax.naming.Context
hibernate.session_factory_name SessionFactory

4. Hibernate creates the non-existent JNDI context for me on webapp start
and puts the session-factory in it.  My facade class opens the session this
way:

Content ctx 

RE: Hibernate plugin

2003-11-24 Thread Ramachandiran, Karuna
Hello Gopal-,
Hibernate is OR/Mapping tool which allows you to map java
data objects to relational database.
The documentation found in the hibernate.org is the best documentation I
have ever seen for a open source project so going thru that will help
you a lot. Basically everyone thinking that JDO is replacement for
entity beans in J2ee but each of them have theor own pros and cons it
depends on which way you gonna go.If you need further help in this one
feeel free to mail me off the list.

Thanks

Karuna

-Original Message-
From: Gopal Venkata Achi [mailto:[EMAIL PROTECTED] 
Sent: Monday, November 24, 2003 10:12 AM
To: Struts Users Mailing List
Subject: RE: Hibernate plugin


Hi David,
We are in the process of choosing the Hibernate for one of my
applications.  Can you let me know, how does it help us, and under what
circumstances, we use this tool.  I have gone thru the Hibernate docs,
but have not got the clear idea. Please help me in this regard. Regards,
gopal

-Original Message- 
From: David Friedman [mailto:[EMAIL PROTECTED] 
Sent: Mon 11/24/2003 12:02 AM 
To: Struts Users Mailing List 
Cc: 
Subject: RE: Hibernate plugin



Mark,

I have a simpler approach for Hibernate (v2.0.3 or v2.1 under
Struts v1.0 or
v1.1)

1. Start with the Hibernate example Struts PlugIn code and
struts-config.xml
configuration text at:
http://www.hibernate.org/105.html

2. Do NOT put any context entries in server.xml or web.xml!

3. Choose any name OTHER than the example
"java:comp/env/jdbc/mn-test".  Any
name under "java:/comp" in Tomcat is read-only and cannot be
used.  I
selected one using my initial and some related hibernate words
"dgf:/hibernate/SessionFactory".  Put that in your
hibernate.cfg.xml file as
the 'name="..."' parameter of the session-factory tag, along the
lines of
this example:







If you use a hibernate.properties file, what you need is
described here:

http://www.hibernate.org/hib_docs/api/net/sf/hibernate/cfg/Environment.h
tml

Since I use hibernate.cfg.xml instead of hibernate.properties,
I'm guessing
you'll need something like this in your hibernate.properties
file:
hibernate.jndi.url dgf:/hibernate
hibernate.jndi.class javax.naming.Context
hibernate.session_factory_name SessionFactory

4. Hibernate creates the non-existent JNDI context for me on
webapp start
and puts the session-factory in it.  My facade class opens the
session this
way:

Content ctx = new InitialContext();
SessionFactory sf = (SessionFactory) ctx.lookup(jndiLocation);
Session session = sf.openSession();

That's all I do.  Oh, I'm using hibernate 2.1beta6 now for my
facade because
it allows me to use named parameters in queries and hide the
hibernate types
more easily.  (sorry, I think I read too much into Ted Husted's
Struts in
Action book, I'm trying to facade EVERYTHING! LOL).

Feel free to email me off-list if you need futher help.

Regards,
David


-Original Message-
From: Mark Lowe [mailto:[EMAIL PROTECTED]
Sent: Monday, November 24, 2003 12:32 AM
To: Struts Users Mailing List
Subject: Hibernate plugin


After spending all night pissing around with various hibernate
plugins
to provide a datasource to use with hibernate?

My JNDI datasource reports being okay in my container log,






..

then in my hibernate.cfg.xml


java:comp/env/jdbc/mn-test


...

Every-time i try and get the datasource from the servlet context
I get
a null pointer exception.. While this of course is a life
changing
experience for me, i novelty is waring thin. If anyone has is
working
in reality , then any input would be greatly appreciated.


Cheers Mark



-
To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]



-
To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]




---

RE: Hibernate plugin

2003-11-24 Thread Gopal Venkata Achi
Hi David,
We are in the process of choosing the Hibernate for one of my applications.  Can you 
let me know, how does it help us, and under what circumstances, we use this tool.  I 
have gone thru the Hibernate docs, but have not got the clear idea.
Please help me in this regard.
Regards,
gopal

-Original Message- 
From: David Friedman [mailto:[EMAIL PROTECTED] 
Sent: Mon 11/24/2003 12:02 AM 
To: Struts Users Mailing List 
Cc: 
Subject: RE: Hibernate plugin



Mark,

I have a simpler approach for Hibernate (v2.0.3 or v2.1 under Struts v1.0 or
v1.1)

1. Start with the Hibernate example Struts PlugIn code and struts-config.xml
configuration text at:
http://www.hibernate.org/105.html

2. Do NOT put any context entries in server.xml or web.xml!

3. Choose any name OTHER than the example "java:comp/env/jdbc/mn-test".  Any
name under "java:/comp" in Tomcat is read-only and cannot be used.  I
selected one using my initial and some related hibernate words
"dgf:/hibernate/SessionFactory".  Put that in your hibernate.cfg.xml file as
the 'name="..."' parameter of the session-factory tag, along the lines of
this example:







If you use a hibernate.properties file, what you need is described here:
http://www.hibernate.org/hib_docs/api/net/sf/hibernate/cfg/Environment.html

Since I use hibernate.cfg.xml instead of hibernate.properties, I'm guessing
you'll need something like this in your hibernate.properties file:
hibernate.jndi.url dgf:/hibernate
hibernate.jndi.class javax.naming.Context
hibernate.session_factory_name SessionFactory

4. Hibernate creates the non-existent JNDI context for me on webapp start
and puts the session-factory in it.  My facade class opens the session this
way:

Content ctx = new InitialContext();
SessionFactory sf = (SessionFactory) ctx.lookup(jndiLocation);
Session session = sf.openSession();

That's all I do.  Oh, I'm using hibernate 2.1beta6 now for my facade because
it allows me to use named parameters in queries and hide the hibernate types
more easily.  (sorry, I think I read too much into Ted Husted's Struts in
Action book, I'm trying to facade EVERYTHING! LOL).

Feel free to email me off-list if you need futher help.

Regards,
David


-Original Message-
From: Mark Lowe [mailto:[EMAIL PROTECTED]
Sent: Monday, November 24, 2003 12:32 AM
To: Struts Users Mailing List
Subject: Hibernate plugin


After spending all night pissing around with various hibernate plugins
to provide a datasource to use with hibernate?

My JNDI datasource reports being okay in my container log,






..

then in my hibernate.cfg.xml


java:comp/env/jdbc/mn-test


...

Every-time i try and get the datasource from the servlet context I get
a null pointer exception.. While this of course is a life changing
experience for me, i novelty is waring thin. If anyone has is working
in reality , then any input would be greatly appreciated.


Cheers Mark


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

RE: Hibernate plugin

2003-11-23 Thread Joe Hertz
Scuse me. I typoed. I meant to say, "Havent shut me down cold". The
happen, and I'd like to know why, but for now, I'm not complaining. 

The reason I didn't go to the Hibernate site (don't laugh too loud) is
that I had problems getting the one from the hibernate site to work too,
and there are things in the struts hibernate example that 1) Need it and
2) I don't feel confident enough to mess with.

Specifically, it uses a DispatchAction class, but defines execute() to
do all of it's hibernate related stuff (again, which I don't feel I
understand terribly well). I scratch my head every time I see this. Why
would you have execute in a DispatchAction? Does it get called before
you do super.execute()?

I'd prefer to go to the one from Hibernate if I knew what I was doing
better :-/



> -Original Message-
> From: David Friedman [mailto:[EMAIL PROTECTED] 
> Sent: Monday, November 24, 2003 1:27 AM
> To: Struts Users Mailing List; [EMAIL PROTECTED]
> Subject: RE: Hibernate plugin
> 
> 
> Shh I don't think I've ever seen any Hibernate errors on 
> startup using the code from the Hibernate site. And it works 
> fine accessing it either through JNDI or a Servlet attribute 
> named SESSION_FACTORY_KEY. :)
> 
> http://www.hibernate.org/105.html
> 
> Regards,
> David
> 
> -Original Message-
> From: Joe Hertz [mailto:[EMAIL PROTECTED]
> Sent: Monday, November 24, 2003 1:29 AM
> To: 'Struts Users Mailing List'
> Subject: RE: Hibernate plugin
> 
> 
> I got it working when I started with the struts-hibernate 
> example that Ted Husted wrote. Used the plugin from it.
> 
> I believe JNDI is avoided entirely with it.
> 
> I get some Hibernate SessionFactory Errors on startup 
> occasionally, but they stopped me cold.
> 
> Fix the addClass() calls here, but otherwise, it goes a 
> little bit like
> this:
> 
> package struts;
> 
> import javax.servlet.ServletException;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpSession;
> 
> import net.sf.hibernate.HibernateException;
> import net.sf.hibernate.MappingException;
> import net.sf.hibernate.Session;
> import net.sf.hibernate.SessionFactory;
> import net.sf.hibernate.cfg.Configuration;
> import org.apache.struts.action.ActionServlet;
> import org.apache.struts.action.PlugIn;
> import org.apache.struts.config.ModuleConfig;
> 
> /**
>  * Initialize the Hibernate SessionFactory for this project
>  * as an application scope object.
>  *
>  * @author Ted Husted
>  * @version $Revision: 1.3 $ $Date: 2003/03/14 21:59:41 $
>  */
> public class HibernatePlugIn implements PlugIn {
> 
> /**
>  * A field to store the reference to our SessionFactory.
>  * Can close and dispose if not null.
>  */
> private SessionFactory sf;
> 
> /**
>  * A public identifer for the persistence session,
>  * kept in servlet session ("client") scope
>  * ["HIBERNATE_SESSION"].
>  */
> public static String SESSION = "HIBERNATE_SESSION";
> 
> /**
>  * A public identifer for the session factory,
>  * kept in application ("global") scope
>  * ["HIBERNATE_SESSION_FACTORY"].
>  */
> public static String SESSION_FACTORY = 
> "HIBERNATE_SESSION_FACTORY";
> 
> /**
>  * Fetch the SessionFactory from application scope.
>  * @param request The requeste we are servicing
>  * @return The SessionFactory for this application session
>  * @throws HibernateException
>  */
> public static SessionFactory sessionFactory(HttpServletRequest
> request)
> throws HibernateException {
> Object sf = 
> request.getSession().getServletContext().getAttribute(SESSION_
> FACTORY);
> if (null == sf) {
> throw new HibernateException(SESSION_FACTORY);
> }
> return (SessionFactory) sf;
> }
> 
> 
> /**
>  * Open a new session with the application-scope SessionFactory.
>  * Session is not retained, only returned.
>  *
>  * @param request The requeset we are servicing
>  * @return An open session
>  * @throws HibernateException
>  */
> public static Session open(HttpServletRequest request) 
> throws HibernateException {
> return sessionFactory(request).openSession();
> }
> 
> /**
>  * Open a new Session and cache it in the HttpSession or
>  * fetch the existing Session.
>  *
>  * @param request The requeset we are servicing
>  * @return An open session
>  

RE: Hibernate plugin

2003-11-23 Thread David Friedman
Shh I don't think I've ever seen any Hibernate errors on 
startup using the code from the Hibernate site. And it works
fine accessing it either through JNDI or a Servlet attribute
named SESSION_FACTORY_KEY. :)

http://www.hibernate.org/105.html

Regards,
David

-Original Message-
From: Joe Hertz [mailto:[EMAIL PROTECTED]
Sent: Monday, November 24, 2003 1:29 AM
To: 'Struts Users Mailing List'
Subject: RE: Hibernate plugin


I got it working when I started with the struts-hibernate example that
Ted Husted wrote. Used the plugin from it.

I believe JNDI is avoided entirely with it.

I get some Hibernate SessionFactory Errors on startup occasionally, but
they stopped me cold.

Fix the addClass() calls here, but otherwise, it goes a little bit like
this:

package struts;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.MappingException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;

/**
 * Initialize the Hibernate SessionFactory for this project
 * as an application scope object.
 *
 * @author Ted Husted
 * @version $Revision: 1.3 $ $Date: 2003/03/14 21:59:41 $
 */
public class HibernatePlugIn implements PlugIn {

/**
 * A field to store the reference to our SessionFactory.
 * Can close and dispose if not null.
 */
private SessionFactory sf;

/**
 * A public identifer for the persistence session,
 * kept in servlet session ("client") scope
 * ["HIBERNATE_SESSION"].
 */
public static String SESSION = "HIBERNATE_SESSION";

/**
 * A public identifer for the session factory,
 * kept in application ("global") scope
 * ["HIBERNATE_SESSION_FACTORY"].
 */
public static String SESSION_FACTORY = "HIBERNATE_SESSION_FACTORY";

/**
 * Fetch the SessionFactory from application scope.
 * @param request The requeste we are servicing
 * @return The SessionFactory for this application session
 * @throws HibernateException
 */
public static SessionFactory sessionFactory(HttpServletRequest
request)
throws HibernateException {
Object sf =
request.getSession().getServletContext().getAttribute(SESSION_FACTORY);
if (null == sf) {
throw new HibernateException(SESSION_FACTORY);
}
return (SessionFactory) sf;
}


/**
 * Open a new session with the application-scope SessionFactory.
 * Session is not retained, only returned.
 *
 * @param request The requeset we are servicing
 * @return An open session
 * @throws HibernateException
 */
public static Session open(HttpServletRequest request) throws
HibernateException {
return sessionFactory(request).openSession();
}

/**
 * Open a new Session and cache it in the HttpSession or
 * fetch the existing Session.
 *
 * @param request The requeset we are servicing
 * @return An open session
 * @throws net.sf.hibernate.HibernateException if session cannot be
instantiated
 */
public static Session reconnect(HttpServletRequest request)
throws HibernateException {

Session s = (Session)
request.getSession(true).getAttribute(SESSION);
if (null != s) {
s.reconnect();
} else {
s = open(request);
request.getSession().setAttribute(SESSION, s);
}
return s;
}

/**
 * Expire the Session, to ensure fresh data or to switch approaches.
 *
 * @param request The requeset we are servicing
 * @return An open session
 * @throws net.sf.hibernate.HibernateException if session cannot be
instantiated
 */
public static void expire(HttpServletRequest request)
throws HibernateException {

HttpSession httpSession = request.getSession();
if (null!=httpSession) {
Session s = (Session) httpSession.getAttribute(SESSION);
if (null != s) {
s.close();
httpSession.removeAttribute(SESSION);
}
}
}

/**
 * The classes with mappings to add to the Configuration are
enumerated here.
 * There should be a "${class}.hbm.xml" mapping file for each class
 * stored with each compiled class file.
 * 
 * To complete the Hibernate setup, there must be a valid
"hiberate.properties"
 * file under the "classes" folder (root of the classpath),
 * which specifies the details of the database hookup.
 * 
 * The mapping documents and properties file is all that Hibernate
requires.
 *

RE: Hibernate plugin

2003-11-23 Thread Joe Hertz
I got it working when I started with the struts-hibernate example that
Ted Husted wrote. Used the plugin from it.

I believe JNDI is avoided entirely with it.

I get some Hibernate SessionFactory Errors on startup occasionally, but
they stopped me cold.

Fix the addClass() calls here, but otherwise, it goes a little bit like
this:

package struts;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.MappingException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;

/**
 * Initialize the Hibernate SessionFactory for this project
 * as an application scope object.
 *
 * @author Ted Husted
 * @version $Revision: 1.3 $ $Date: 2003/03/14 21:59:41 $
 */
public class HibernatePlugIn implements PlugIn {

/**
 * A field to store the reference to our SessionFactory.
 * Can close and dispose if not null.
 */
private SessionFactory sf;

/**
 * A public identifer for the persistence session,
 * kept in servlet session ("client") scope
 * ["HIBERNATE_SESSION"].
 */
public static String SESSION = "HIBERNATE_SESSION";

/**
 * A public identifer for the session factory,
 * kept in application ("global") scope
 * ["HIBERNATE_SESSION_FACTORY"].
 */
public static String SESSION_FACTORY = "HIBERNATE_SESSION_FACTORY";

/**
 * Fetch the SessionFactory from application scope.
 * @param request The requeste we are servicing
 * @return The SessionFactory for this application session
 * @throws HibernateException
 */
public static SessionFactory sessionFactory(HttpServletRequest
request)
throws HibernateException {
Object sf =
request.getSession().getServletContext().getAttribute(SESSION_FACTORY);
if (null == sf) {
throw new HibernateException(SESSION_FACTORY);
}
return (SessionFactory) sf;
}


/**
 * Open a new session with the application-scope SessionFactory.
 * Session is not retained, only returned.
 *
 * @param request The requeset we are servicing
 * @return An open session
 * @throws HibernateException
 */
public static Session open(HttpServletRequest request) throws
HibernateException {
return sessionFactory(request).openSession();
}

/**
 * Open a new Session and cache it in the HttpSession or
 * fetch the existing Session.
 *
 * @param request The requeset we are servicing
 * @return An open session
 * @throws net.sf.hibernate.HibernateException if session cannot be
instantiated
 */
public static Session reconnect(HttpServletRequest request)
throws HibernateException {

Session s = (Session)
request.getSession(true).getAttribute(SESSION);
if (null != s) {
s.reconnect();
} else {
s = open(request);
request.getSession().setAttribute(SESSION, s);
}
return s;
}

/**
 * Expire the Session, to ensure fresh data or to switch approaches.
 *
 * @param request The requeset we are servicing
 * @return An open session
 * @throws net.sf.hibernate.HibernateException if session cannot be
instantiated
 */
public static void expire(HttpServletRequest request)
throws HibernateException {

HttpSession httpSession = request.getSession();
if (null!=httpSession) {
Session s = (Session) httpSession.getAttribute(SESSION);
if (null != s) {
s.close();
httpSession.removeAttribute(SESSION);
}
}
}

/**
 * The classes with mappings to add to the Configuration are
enumerated here.
 * There should be a "${class}.hbm.xml" mapping file for each class
 * stored with each compiled class file.
 * 
 * To complete the Hibernate setup, there must be a valid
"hiberate.properties"
 * file under the "classes" folder (root of the classpath),
 * which specifies the details of the database hookup.
 * 
 * The mapping documents and properties file is all that Hibernate
requires.
 * 
 * A JDBC Driver is not included in this distribution and *must* be
 * available on your server's or container's classpath
 * (e.g., the Tomcat common/lib directory).
 *
 * @return A Configuration object
 * @throws net.sf.hibernate.MappingException if any the mapping
documents can be rendered.
 */
private static final Configuration createConfiguration()
throws MappingException {
return new Configuration()
.addClass(bb.hibernate.Eyecolorcode.class)
.addClass(bb.hibern

RE: Hibernate plugin

2003-11-23 Thread David Friedman
Mark,

I have a simpler approach for Hibernate (v2.0.3 or v2.1 under Struts v1.0 or
v1.1)

1. Start with the Hibernate example Struts PlugIn code and struts-config.xml
configuration text at:
http://www.hibernate.org/105.html

2. Do NOT put any context entries in server.xml or web.xml!

3. Choose any name OTHER than the example "java:comp/env/jdbc/mn-test".  Any
name under "java:/comp" in Tomcat is read-only and cannot be used.  I
selected one using my initial and some related hibernate words
"dgf:/hibernate/SessionFactory".  Put that in your hibernate.cfg.xml file as
the 'name="..."' parameter of the session-factory tag, along the lines of
this example:







If you use a hibernate.properties file, what you need is described here:
http://www.hibernate.org/hib_docs/api/net/sf/hibernate/cfg/Environment.html

Since I use hibernate.cfg.xml instead of hibernate.properties, I'm guessing
you'll need something like this in your hibernate.properties file:
hibernate.jndi.url dgf:/hibernate
hibernate.jndi.class javax.naming.Context
hibernate.session_factory_name SessionFactory

4. Hibernate creates the non-existent JNDI context for me on webapp start
and puts the session-factory in it.  My facade class opens the session this
way:

Content ctx = new InitialContext();
SessionFactory sf = (SessionFactory) ctx.lookup(jndiLocation);
Session session = sf.openSession();

That's all I do.  Oh, I'm using hibernate 2.1beta6 now for my facade because
it allows me to use named parameters in queries and hide the hibernate types
more easily.  (sorry, I think I read too much into Ted Husted's Struts in
Action book, I'm trying to facade EVERYTHING! LOL).

Feel free to email me off-list if you need futher help.

Regards,
David


-Original Message-
From: Mark Lowe [mailto:[EMAIL PROTECTED]
Sent: Monday, November 24, 2003 12:32 AM
To: Struts Users Mailing List
Subject: Hibernate plugin


After spending all night pissing around with various hibernate plugins
to provide a datasource to use with hibernate?

My JNDI datasource reports being okay in my container log,






..

then in my hibernate.cfg.xml


java:comp/env/jdbc/mn-test


...

Every-time i try and get the datasource from the servlet context I get
a null pointer exception.. While this of course is a life changing
experience for me, i novelty is waring thin. If anyone has is working
in reality , then any input would be greatly appreciated.


Cheers Mark


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]