• 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

Database Choice with hibernate

 
Greenhorn
Posts: 23
Eclipse IDE Tomcat Server Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been spending the last few months trying to learn JSF. Because applications always use data, the choice for an appropriate database was the next issue I was confronted with.
I develop with eclipse, Tomcat 6, myFaces and tried my first project using HSQLDB. Right now I am starting to finally starting to understand some of the concepts and have been programming a practice project with an Apache Derby Database. I really like use an identity ID so that I don't have to worry about incrementing the ID field. But Hibernate doesn't suppport identity fields in Derby(?). My purpose is to learn JSF and the dependent technologies. It's not about a huge RDBMS or something highly performant.

My question is: for general web applications with hibernate, is there a standard or a reccomended database that has a high acceptance within the developer community? i.e. PostgreSQL, MYSQL ...

I realize that it depends on the requirements of a project, but maybe someone has a good reccomendation that would also be a well-accepted DB in the Java "World" Any tips or information would be appreciated.
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

t Hibernate doesn't suppport identity fields in Derby(?).



Sure it does. It supports all the generation strategies except sequence. I use Derby all the time for local development(client) and testing(embedded). It has served me exceptionally well for this purpose especially when my test/stage/prod environments run DB2 since they are almost syntactically equal in many respects. I know people have used it in production applications but I am not one of them so I can not comment to that.

PostgreSQL and MYSQL are both good choices and either one would serve your purpose as well.

You can look at this page for some comparisons, it is wikipedia so it might not be 100% accurate, but for something like this it probably is fairly accurate.
http://en.wikipedia.org/wiki/Comparison_of_relational_database_management_systems
 
Scott Stephens
Greenhorn
Posts: 23
Eclipse IDE Tomcat Server Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is what I get when I try to

java.sql.SQLSyntaxErrorException: Attempt to modify an identity column 'PERSON_ID'.

My mapping file looks like this:

 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using Identity as generation type is the way to go. What error do you get when using the saveOrUpdate method?
 
Scott Stephens
Greenhorn
Posts: 23
Eclipse IDE Tomcat Server Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I instansiated my object (with id) and now using "identity" strategy I get a null pointer exception when I do a session.save
why does hibernate do a getId() when the identity generator class is used? I would think it wouldn't need the attribute because it gets generated new.

java.lang.NullPointerException
model.Stammdaten.getId(Stammdaten.java:61:

From the Tomcat console :
Initial SessionFactory creation failed.org.hibernate.PropertyAccessException: Exception occurred inside getter of model.Stammdaten.id


Any ideas?
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What was the error you got when using the identity strategy? When using the identity strategy you are not setting the id correct? That should be done by the database. Also your DDL should define that. Using Derby as an example since it was mentioned.

This will allow you to set the identity if you do not provide it it will use the generation strategy. If instead you use GENERATED ALWAYS you must never try to insert an ID.
 
Scott Stephens
Greenhorn
Posts: 23
Eclipse IDE Tomcat Server Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The above mentioned is the error that comes when I use identity.
I don't set the id field at all. The data is in a managed bean. The variable sd is instansiated at class loading. id is set to null.
The DAOStammdaten.save() function is called from JSF per EL



sdHandler.saveStammdaten just calls the DAO function keeping the business logic in it's layer.
 
Scott Stephens
Greenhorn
Posts: 23
Eclipse IDE Tomcat Server Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here the error msg that is displayed in the browser:
org.hibernate.PropertyAccessException: Exception occurred inside getter of model.Stammdaten.id
org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:172)
org.hibernate.engine.UnsavedValueFactory.getUnsavedIdentifierValue(UnsavedValueFactory.java:67)
org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:67)
org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:147)
org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:457)
org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:131)
org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:261)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
dao.HibernateUtil.<clinit>(HibernateUtil.java:12)
dao.DAOStammdaten.saveStammdaten(DAOStammdaten.java:74)
 
James Boswell
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post your code for the Stammdaten class?
 
Scott Stephens
Greenhorn
Posts: 23
Eclipse IDE Tomcat Server Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I now have both session.save and session saveOrUpdate working!! However with a table that is not identity. For now a good step. I have in my mapping file class="assigned" and assign the id after getting a list and finding the size +1
I am still working on many of the concepts, so it takes a while to sort through some of the details- when class="assigned", the id has to be set before you can use an EL-Expression in a JSF Page. Otherwise, it says Null pointer.

 
Scott Stephens
Greenhorn
Posts: 23
Eclipse IDE Tomcat Server Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the Derby database on another table to use identity and it works fine for a session.save.
 
reply
    Bookmark Topic Watch Topic
  • New Topic