Wednesday, September 26, 2007

Data Persisternt

After install MySQL:

sudo /etc/init.d/mysql stop

mysqladmin -u root password myPassword

mysql -u root -p

sudo /etc/init.d/mysql start

Current ID and PS
ID: root
PS: root

Unit Test, Add this to project.properties
maven.junit.fork=true

Reason:
http://forum.springframework.org/archive/index.php/t-23057.html

Finally, my Hibernate is working,

NB>the object ID value cant be set by programmer, it will specify by the application, which is hibernate or database.
Many legacy SQL data models use natural primary keys. A natural key is a key with
business meaning: an attribute or combination of attributes that is unique by virtue
of its business semantics. Examples of natural keys might be a U.S. Social Security
Number or Australian Tax File Number. Distinguishing natural keys is simple: If a
candidate key attribute has meaning outside the database context, it’s a natural
key, whether or not it’s automatically generated.
Experience has shown that natural keys almost always cause problems in the
long run. A good primary key must be unique, constant, and required (never null
or unknown). Very few entity attributes satisfy these requirements, and some that
do aren’t efficiently indexable by SQL databases. In addition, you should make
absolutely certain that a candidate key definition could never change throughout
he lifetime of the database before promoting it to a primary key. Changing the
definition of a primary key and all foreign keys that refer to it is a frustrating task.
For these reasons, we strongly recommend that new applications use synthetic
identifiers (also called surrogate keys). Surrogate keys have no business meaning—
they are unique values generated by the database or application. There are a num-
ber of well-known approaches to surrogate key generation.

from Hibernate in Action Page90 -Page91
Also, the ID should be int, short or long. Cant be String!!!!!!
Again, don't give value to ID.

I have tried some unit tests. I planned to do this by the end, but the code is too many to test, and debug, so the only wayto narrow your test and find the problem is pick up Unit Test. The Test-Record really helps.

No comments: