• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate DAO Method Naming Conventions for basic CRUD operations

 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm just doing some hibernate, and was wondering what the naming conventions for data access objects were? Are getter methods perferred because we are essentially using a POJO paradigm?

For example:

When getting a record for a User object by primary key, what's the way to name that? With EJBs, it would be findByPrimaryKey(int key) or something? What would we use in a Hibernate app? get(int key)? getByPrimaryKey(int key)?

What about a full table request? EJBs would have a method called findAll(). What is it with Hibernate? I've seen a method called List used, but I don't like the fact that a method named list conflicts with the Hibernate Session's list() method. Do we call the method getAll()?

So, what are the conventions for:

Create Methods? ***Just call them create(argument list)?***
Delete Methods? ***Just call them delete?***
Update Methods? ***Just call them update?***
Finder/Getter Methods? ***retrive? get? find?***

Thanks,

-Cameron McKenzie
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Um, don't recall there being any specific conventions out there. findBy, save, update, all sound good to me.

Mark
 
Ranch Hand
Posts: 330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Cameron McKenzie:
I'm just doing some hibernate, and was wondering what the naming conventions for data access objects were? Are getter methods perferred because we are essentially using a POJO paradigm?

For example:

When getting a record for a User object by primary key, what's the way to name that? With EJBs, it would be findByPrimaryKey(int key) or something? What would we use in a Hibernate app? get(int key)? getByPrimaryKey(int key)?

What about a full table request? EJBs would have a method called findAll(). What is it with Hibernate? I've seen a method called List used, but I don't like the fact that a method named list conflicts with the Hibernate Session's list() method. Do we call the method getAll()?

So, what are the conventions for:

Create Methods? ***Just call them create(argument list)?***
Delete Methods? ***Just call them delete?***
Update Methods? ***Just call them update?***
Finder/Getter Methods? ***retrive? get? find?***

Thanks,

-Cameron McKenzie





in the past i've used persist, get, and delete. my get method for objects requiring key is get<EntityName>(key). for example:



in cases where my hibernate mapping defines a composite key, i pass in an object that encapsulates the multiple attributes that form the key.


for find, what i've done in the past is pass a search object criteria to my finder method. for example:



my find method would then look something like



of course not all criteria may be specified so in my dao i would only use attributes in my EmployeeSearchCriteria object that has a value.


hope this makes sense.
 
reply
    Bookmark Topic Watch Topic
  • New Topic