-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 
Author Message
 Post subject: Swing/Hibernate sample code
PostPosted: Tue Dec 28, 2004 7:15 am 
Newbie

Joined: Thu Nov 04, 2004 10:24 am
Posts: 17
I'm developing a Swing application that will use Hibernate. This would involve reattaching objects held in the Swing presentation layer, and starting a Hibernate session on each iteration of the Swing event loop.

Can anyone point me to an example of a Swing app that uses Hibernate?

Thanks,

Joshua


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 8:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
starting a hibernate session in each swing event loop sounds like an extreme overkill - what about simple mouse movements, do you want a session for that ?

A better choice would probably be to do it via a subclass of Action if it is at all possible to define when to start and stop a session that easy in your swing app

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Hibernate and Swing
PostPosted: Tue Dec 28, 2004 9:07 am 
Newbie

Joined: Thu Nov 04, 2004 10:24 am
Posts: 17
Thank you for the response about Hibernate and Swing.

So when do I start a Session? Any event-loop-run which causes painting of the screen or which changes the object model might need access to the DB. I want to choose a correct Session scope as described in http://www.hibernate.org/168.html , so I don't want to simply let the Session stay open.

Quote:
> A better choice would probably be to do it via a subclass of Action

OK, javax.swing.Action is good for most significant actions, where an Listener is already in place. But all sorts of Swing events, such maximizing the screen, switching away from my app and back to it, or scrolling, automatically cause the painting of new objects on the screen. These would need to be loaded through Hibernate. Do we need to listen for every single event that might necessitate painting something on the screen?

Could you refer me to an example of a Swing app that uses Hibernate? That might help clarify these points.

Thanks,

Joshua


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 9:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i don't have a pointer to a swing app sorry. Maybe someone else in the community has one.

I would not recommend loading objects each time you need to repaint the screen in swing - that will be insanely slow!

You need to think about how you define an application transaction in your swing client - in webapps its "easier" since there are natural start and stops (namely start and stop for http requests)....

...but in a swing app you don't have such a natural place - that depends solely on how you application works.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Swing and Hibernate
PostPosted: Tue Dec 28, 2004 9:45 am 
Newbie

Joined: Thu Nov 04, 2004 10:24 am
Posts: 17
Quote:
You need to think about how you define an application transaction in your swing client

For write-transactions, it's easy. These are already encapsulated in Actions in the code.

But read-only-transactions may occur in a great variety of Swing events.

Imagine an app that is nothing but a JTable pointing to a gigantic table in the DB. Then of course the standard design is not to load the whole model into memory in advance. Rather, Swing will trigger the renderer for a given node only when needed, and then the relevant objects will be loaded from the DB.

In that case, though, I need to start a Session if one is not yet started. So, does each rendered need to be aware of the possibility that a Session might need to be started?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 9:49 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Joshua,

I make generic swing client with hibernate (form with CRUD, report, smart search, sorting,
aggregate function etc) see description on http://www.snpe.co.yu/html/snpedevel.html

It is on my native language and it is alpha, but I make english transaltion and demo, soon

regards
Peco


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 9:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Again, how would you do this in you application without Hibernate and with plain JDBC ?

I don't have written good (or bad) patterns for doing this stuff, but
normally I simply give all the data to the table models or I let the Table model talk to a facade that handles the opening/closing of a session.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 10:04 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
I can't do it without hibernate

My pattern is simple : hibernate read xxx rows in data model (extends AbstractList) and I have
termin : current bean, new bean etc and list - from list I make tablemodel etc
In search user populate data in bean (form) and I in background create hql query to database
It is same for grouping functions - complete stuff is generic : forms, report, grouping, sorting searching - developer make only visual stuff

operation like : create row, delete row or change row do hibernate too.

regards


Top
 Profile  
 
 Post subject: Swing/Hibernate
PostPosted: Tue Dec 28, 2004 10:14 am 
Newbie

Joined: Thu Nov 04, 2004 10:24 am
Posts: 17
Max,

Quote:
Again, how would you do this in you application without Hibernate and with plain JDBC ?

Yes, this would be quite difficult. The challenges would be similar in plain JDBC, in JDO, Toplink, or any other approach.

There are not too many complex Swing apps that are directly based on a DB backend. However, this is the classic Client/Server architecture, and I'm looking into ways of doing it. I'll let you know if I discover any design patterns.

Joshua


Top
 Profile  
 
 Post subject: snpedevel: Swing/Hibernate
PostPosted: Tue Dec 28, 2004 10:30 am 
Newbie

Joined: Thu Nov 04, 2004 10:24 am
Posts: 17
Snpesnpe , I'd love to get a copy of snpedevel if you could email one to joshua<AT>unicorn . com or if you could send the precise URL for download--I can't find the download link as I do not read the language.


Top
 Profile  
 
 Post subject: Swing and Hibernate
PostPosted: Tue Dec 28, 2004 11:37 am 
Newbie

Joined: Thu Nov 04, 2004 10:24 am
Posts: 17
One of the developers on my team came up with an idea for our Swing application (in which there is a single DB updated only by the one app, which means fewer data consistency issues).

Open a Session at the beginning of each write-Action and leave it open until the beginning of the next write-Action. Read-only data accesses such as, scrolling to a different part of a JList, never have to reattach detached objects.

This is a variant of the Session-per-User-Transaction design pattern (http://www.hibernate.org/168.html). It does mean that Sessions can be open for a long time between Transactions.

This relies on never having any Hibernate exceptions in the read-only data accesses, otherwise the Session is messed up until the next write-Action begins.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 1:23 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Joshua,
There isn't download link.It is our internal software - we migrate legacy application to swing with hibernate

regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.