Possibly a simple (read dumb) question. I am in design phase of a web application - standard Spring MVC and planning on using Spring DAO support (jdbctemplate - no hibernate & no ibatis etc).
I am currently modeling my data objects for the RDBMS. What is the best practise for data types? Let's say my primary key of a table is Numeric - Do I model that in my object as Long or long? Any p开发者_如何学Goroblem / advantage of one over another?
Gurus?
Long is nullable. So an object with a null id (in Java) can represent an object that is not (yet) persisted. You can explicitly configure Hibernate to treat it that way, and if you don't use Hibernate, it's still good practice to give you DAO methods a way of finding out whether a particular object is already in the database or not.
I prefer to have a type "Identity" that is Serializable (Comparable, Clonable etc) and which String representation is used e.g. to build URLs. Only the DAO implementation knows which exact type it is. It could be Long or it could be a combined primary key. Above the Data Access layer, the application only deals with the Identity.
If the identity is null, the object is not persisted (has no identity assigned via the persistence store).
精彩评论