assigned: The Java application is responsible for generating (i.e. manual assignment)
native: The underlying database automatically generates identifiers. If it is MySQL, it is auto_increment, if it is Oracle, it is sequence, etc.
When operating, you still need to combine the hibernate.cfg.xml file, because if the hbm2ddl.auto property in the database is updated, it is OK to set the primary key to increase automatically; but if it is created, if it is not manually changed the second time, a bug may occur.
Generally speaking, you can just follow the Java data type.
The most error-prone data types are date and timestamp.
- The date type can be mapped to java.util.Date or java.sql.Date type. Representative date: yyyy-MM-dd
- Time type maps to the time represented by java.util.Time and java.sql.Time: hh:mm:ss
- timesaamp can be mapped to java.util.Date or java.sql.TimeStamp type, representing the time and date: yyyymmddhhmmss
How to change the database type in its Azi database?
Change the type property of the class object's property in the XX.hbm.xml file. Just change it to the data type that comes with Hibernate.
Here is a summary of the object types supported by Hibernate:
When operating, you only need to follow the corresponding API.
It should be noted that MySQL does not support the standard CLOB type. In MySQL, TEXT, MEDIUMTEXT and LONGTEXT types are used to represent long text data with a length of more than 255.
An object in an entity class belongs to a user-defined class
like:
<component name="address"> <property name="postcode" column="POSTCODE" /> <property name="phone" column="PHONE" /> <property name="address" column="ADDRESS" /></component>
That is to say, once it is a user-defined type, the component tag should be used in the XX.hbm.xml file, rather than the simple property tag. This should be paid attention to.
Here we mainly use several commonly used APIs for session. Such as save, update, delete, and get/load, etc.
- save: directly call session.save (instance of the object)
- get/load: session.get/load(XX.class, identifier); where this identifier can be the value corresponding to the primary key
- update:session.update (instance of object)
- delete:session.delete(instance of object)
- 1. Without considering cache, the get method sends SQL statements to the database immediately after being called, returning a persisted object, while the load method returns a proxy object after being called. The proxy object only saves the id of the entity object and will issue an SQL statement when it knows the non-primary key attributes of the applicable object.
- 2. When querying data that does not exist in the database, the get method returns null, and the load method will throw an exception org.hibernate.ObjectNotFoundException
The above is all the content of this article about the analysis of Hibernate single table operation examples, I hope it will be helpful to everyone. Interested friends can continue to refer to other related topics on this site. If there are any shortcomings, please leave a message to point it out. Thank you friends for your support for this site!