File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DAO create method setting object id...

 
Samuel Cox
Ranch Hand
Posts: 96
Scala Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a question about coding style. I'm implementing the CRUD methods for my various DAOs and am considering having my create statement set the id of the object argument that it is receiving.

For example,



The DAO that includes this DAO would then use the id as a foreign key during its create method.

My functional programming instructor would cry foul at this design. I'm looking for opinions. Am I way off? Should the method return the id and then set the id in the bean?

Any thoughts are welcome.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, this is in the ORM forum however you didn't mention if you are using an ORM technology or not. So let's pretend you are using Hibernate. When you had Address to your create method and then do something like:

session.save(address)

address will then have the autognerated ID already. iBatis does the same thing. Now, if you are using plain JDBC then I don't see a problem with putting the ID in the address object in your DAO.
 
Samuel Cox
Ranch Hand
Posts: 96
Scala Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using JDBC to populate my DAO. I did consider posting my question in the JDBC forum, but assumed this one was better since I'm questioning design principles of code that moves information from a relational database to an object, which I consider ORM.

Is this forum only for discussion of ORM solutions such as Hibernate, iBatis, etc? Not trying to be cute, just need to know for future posts.

Thanks for the reply.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic