• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can I include model inside model if using JDBC Dao pattern?

 
Winston Liek
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets say
I have 2 tables: Person and Address. Both have int primary keys.
Address table has constraint with Person.

My questions is what is the best content of Address model referencing to Person? I'll be using JDBC dao pattern as I need to process large data (based from what I researched, JDBC is better than hibernate in terms of performance)
Is it:

public class Address{
private int personId;
}

or

public class Address{
private Person person;
}


I think second option is more clear... But how do you handle insert or update?

And also, is there a plugin in eclipse that can generate model classes from database tables from a Maven project? I only could see tutorial on JPA project but not on maven.

TIA


 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on your needs. Does the code always use the Person object when it gets an address? If so, you might as well get them at once with your option 2. For insert and update, you have a choice. You can have two DAOs that each insert/update their own. Or you can have a shared DAO that updates them both together regardless of whether there have been any changes.

Well designed Hibernate/JPA is the same in performance as JDBC.

As far as generating, you can use a JPA/Hibernate generation tool. Just have it generate without annotations. (or delete the annotations.) I don't like the generation tools though because I don't always have the same names in my database as my Java code.
 
Winston Liek
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks.

Does hibernate perform the same if I need to perform crud for around 2000 data at once?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Liek wrote:Does hibernate perform the same if I need to perform crud for around 2000 data at once?

It depends on how you write it. Hibernate creates SQL under the covers. You can do bulk updates that get translated to efficient SQL. But you have to design your code efficiently.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic