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.
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.
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.
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.
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.
here the error msg that is displayed in the browser:
org.hibernate.PropertyAccessException: Exception occurred inside getter of model.Stammdaten.id
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.