aspose file tools*
The moose likes Object Relational Mapping and the fly likes Do you have a common save/update/delete method in your app? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Do you have a common save/update/delete method in your app?" Watch "Do you have a common save/update/delete method in your app?" New topic
Author

Do you have a common save/update/delete method in your app?

Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 498
If you have many DB tables and you need to perform save/update/delete operations, do you have a common method for each table or separate methods (like saveEmployee(Employee employee), saveEmployer(Employer employer) etc)?

I know Hibernate session's save method accepts object of Object class. Do you implement in this way?

Or you have a common parent class(let's say class Parent)which each model has to extend and in your custom save method you accept object of Parent class?

Please share.
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 484

Saurabh Pillai wrote:If you have many DB tables and you need to perform save/update/delete operations, do you have a common method for each table or separate methods (like saveEmployee(Employee employee), saveEmployer(Employer employer) etc)?

I know Hibernate session's save method accepts object of Object class. Do you implement in this way?

Or you have a common parent class(let's say class Parent)which each model has to extend and in your custom save method you accept object of Parent class?

Please share.


I prefer using Hibernate because it saves me a lot of time! For a simple application, I would code the database operations manually, without using Hibernate.


PM Me If You Want to get Urgent Help on Java Programming
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 498
I am also using Hibernate only. and in that regard only I asked the question. OK I guess I complicated the question. Let me ask simple question,

How do you implement save method using Hibernate in your app?

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15629
    
  15

Normally I have a DAO class for each primary table. This DAO not only implements the save/update/delete methods, it also contains the finder methods. It isolates the low-level functionality, making maintenance and testing easier. In particular, since finders often contain complex Query Language, and QL is interpreted, not compiled, having everything in one class makes it easier to dynamically test the QL syntax using something like DBUnit without having to bring up a heavy runtime system.

For really complex stuff, I also have a persistent services layer above the DAO layer. Persistent services use DAOs (sometimes several different DAOs) in order to properly co-ordinate complex relationships between objects. The service methods are transactional, so that the entire network of objects for that function are controlled as a unit that can be atomically committed or rolled back.


Customer surveys are for companies who didn't pay proper attention to begin with.
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 498
Tim Holloway wrote:Normally I have a DAO class for each primary table. This DAO not only implements the save/update/delete methods, it also contains the finder methods.


Hi Tim,

Thank you for your reply.

In my case I am thinking about having single common save method like this rather having individual save methods per DAO,


What do you think?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

Common operations such as save, update etc... can be implemented in a generic DAO class which can be extended by each DAO implementations in which they delegate the task to the super class.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Do you have a common save/update/delete method in your app?
 
Similar Threads
How Struts will identify Class (with get / set methods) associated with it
System.out.println(Set); what does it prints actually????
Dynamic Delete
create objects of my classes dynamically and put them into linkedlist
How to retrieve the first record in a database table