Ever been developing with Hibernate, and wished something would save your Time and Sanity? Here it is!
http://ndpsoftware.com/HibernateMappingCheatSheet.html
Showing posts with label Hibernate. Show all posts
Showing posts with label Hibernate. Show all posts
Sunday, June 7, 2009
Wednesday, June 3, 2009
Hibernate again
This time , i'm posting here something that did not work for me , however i have found a nice workaround.
The hibernate projection will have to wait
SELECT NAME FROM PRODUCT
Here, the Projection class comes into play. The above query can be rewritten into a Criteria query as:
List products=session.createCriteria(Product.class)
. setProjection(Projection.property(\"name\"))
.list();
Sunday, May 10, 2009
Hibernate - how to add a new table
hibernate creating new table
checklist
1. create the table in the database
2. create the class only members this time
3. create the hbm.xml file with mapping of the class members to the
4. update the hibernate.cfg.xml with the new hbm file you have created
5. create the test - and make it fail (c'mon in never works on the first time )
more is comming
- foreign keys
- pictures
- more detailed how to
Monday, February 16, 2009
Hibernate Unique Ids
It seems that hibernate does not really like working with unique ids in the database (we experiemented it when using the embedded version in Gigaspaces).
A way to overcome the issue, is adding a new field to the database, which will be used as unique field, and its value will be generated on the fly in the application level.
The unique value can be generated using the relevant API (GUID in MS) and UUID in Java:
import java.util.UUID;
public class GenerateUUID {
public static final void main(String... aArgs) {
//generate random UUIDs
UUID idOne = UUID.randomUUID();
UUID idTwo = UUID.randomUUID();
log("UUID One: " + idOne);
log("UUID Two: " + idTwo);
}
private static void log(Object aObject){
System.out.println( String.valueOf(aObject) );
}
}
A way to overcome the issue, is adding a new field to the database, which will be used as unique field, and its value will be generated on the fly in the application level.
The unique value can be generated using the relevant API (GUID in MS) and UUID in Java:
import java.util.UUID;
public class GenerateUUID {
public static final void main(String... aArgs) {
//generate random UUIDs
UUID idOne = UUID.randomUUID();
UUID idTwo = UUID.randomUUID();
log("UUID One: " + idOne);
log("UUID Two: " + idTwo);
}
private static void log(Object aObject){
System.out.println( String.valueOf(aObject) );
}
}
Thursday, February 12, 2009
Hibernate: Log SQL Statements
It's very useful when debbuging Hiberante based system to be aware of the SQL output that is being sent to the database (like the old phrase Garbage In Garbage Out)
There are two methods to do that:
1. Enable hiberante logging
2. Enable the RDBMS log files, for example: Enable MySQL SQL logging
There are two methods to do that:
1. Enable hiberante logging
2. Enable the RDBMS log files, for example: Enable MySQL SQL logging
Labels:
Debugging,
Hibernate,
Logging,
MySQL,
Slow queries
Subscribe to:
Posts (Atom)