This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Are these two options Hibernate healty ?  RSS feed

 
clojure forum advocate
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
As you know, we should return exactly the same collection instance from the getter method as Hibernate passed to the setter method.
CaveatEmptor use the following :

I was thinking about two variants :
1.

2.

Are the previous two falvors healty in Hibernate context ? (no unnecessary updates) ?
 
Bartender
Posts: 20107
101
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if I understood that correctly, but I'm pretty sure that if what you're looking for is to have a persistent object that can be constructed either by a default (no-argument constructor) or by one or more non-default constructors (which initialize whatever they want), that that's not only legal, but quite proper. I'm pretty sure that I've done exactly that using JDO, in fact. The only stricture is that in addition to whatever other constructors you define, you must define the no-argument (default) constructor.

To be on the safe side, I'd recommend initializing the persisted fields using their setters and getter, rather than by taking advantage of their direct internal access, but other than that, I don't think you'll have any issues.
 
ranger
Posts: 17344
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The big key to an ORM is to make in unobtrusive. So in Hibernate your Java objects are just that Java Objects, built the way you would build a Java object. No extending or implementing classes/interfaces to make it a "persistable" object. So what works in POJOs (Plain Old Java Object) works with Hibernate.

Mark
 
Hussein Baghdadi
clojure forum advocate
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I know.
Returning a collection from a getter method other than the one we passed using the setter, Hibernate will issue unnecessary SQL statements.
So my original question is : If I used one if my flavors, any unnecessary SQL statements will be used ?
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are trying to second-guess Hibernate too much. What SQL is issued will be controlled by the mapping of the association or any explict fetch strategy you are have using. Trying to control it by redesigning your POJO to be a not-so-POJO is not a fool proof way of controlling the SQL Hibernate may issue because its not the POJO itself that influences this aspect of the ORM.
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!