. Import Hibernate.jar and its dependent packages, the jar package has been provided in the above blog, no longer repeat here. 3. Write the Department.hbm.xml and Employee.hbm.xml mapping files, the code is implemented as follows:The "Many-to-one" part of Employee.hbm.xml is the focus, through which the association between department object and employee is established. 4. Write the Hibernate.cfg.xml configuration file, the code is implemented as f
obtain student information, corresponding to a relational model such as:1. Basic ConfigurationWith the object model, let's map them to the corresponding relationship code, add the classes Classes and mapping filesIt is the most important end of the model, at which the corresponding set property needs to be added, and in the configuration file to add the set tag, the set label to configure the corresponding The Set property is used in the classes obje
Then on a few blogs, hibernate mapping relationship, today we talk about the last of the basic relationship: many-to-many.one, many-to-many relationshipsPhenomenon: Many-to-many relationship, in life is very common in the relationship between the students and elective courses, a student can choose more than one elective course, and each elective course can be more than a choice of students. There is a lot
type does not require an identifier attributeSee the code:Step One:Create JavaBean//Step One: Create Emphomeaddress and Empinfo Public classemphomeaddress {PrivateString Ehomestreet; PrivateString ehomecity; PrivateString ehomeprovince; PrivateString Ehomezipcode; Privateempinfo Empinfo;} Empinfo is created as follows: Public classEmpinfo {PrivateInteger Eid; PrivateString ename; Privateemphomeaddress ehome;}Step Two: Create a configuration file EmpInfo.hbm.xmlMapping Public"-//
Citation: http://blog.csdn.net/xvshu/article/details/39187779A recent project has a demand, there are n assessment units, to each unit of assessment to generate a checklist, the purpose of this is to cross-cutting the database, this requirement of implementation, my team members encountered a technical problem, I will my solution and the whole thinking process with you to share,Ideas:With a configuration file, a class is used to map multiple tables (each table has the same structure). According
"Hibernate" about using a join table to implement a one-to-many association mapping A one-to-many association mapping based on an intermediate table is still more common.Person (people) and group (group)Annotations Configuration@Entity @table (name= "T_group") publicclass Group { private Integer ID; private String name; Private set@Entity @table (name= "
1. Mapping rules for federated primary keys1) Each primary key attribute in the class corresponds to each primary key column in the data table.Hibernate requires an entity class with a federated primary key to implement the serializable interface, and overrides the hashcode with the Equals method, because hibernate determines whether a two-row record is the same based on the Federated primary key of the dat
Two or one-to-many (unidirectional)Bean: Public classCarImplementsserializable{Private intID; PrivateString name; Privateuser User; ....} Public classUserImplementsSerializable {Private intID; PrivateString name; PrivateSetcars; ....}XML configuration:Car.hbm.xml:classname= "Car"> ID is to configure the primary key name is the attribute in the class and the primary key mapping generator: The Generation policy that represents the primary key -
Step 1: Case code.Step 2: Case diagram analysis.------------------------------------------------------------------------Step 1: Case code----------------------------------------- --------------------------------------------------------------------------When we explain hibernate many-to-one mapping, the first thing to think about is the classic many-to-one relationship, employees and departments, and let's s
inserted after the department (depart), it generates three database statements//Because the EMP depart_id field is not inserted after both insertions, so there is a last statement to insert Tx.commit (); return depart ;} Finally{if (s!=null) {s.close ();}}} static Employee query (int empId) {Session s = null; Transaction tx = Null;try{s = Hibernateutil.getsession (); tx = S.begintransaction (); Employee EMP = (employee) s.get (Employee.class, empId); Query System.out.println (Emp.getname ()) by
The association relationship in 1.Hibernate can be divided into:
One-way relationship: Only one table points to another table.
Bidirectional relationship: Tables and tables can be pointed to each other.
2. Depending on the associated table, it can be divided into:
1 to 1 relations
1 to multiple relationships
Multi-Many-to-many relationships
For example: 1 customers can correspond to multiple orders, is 1 to many of the relationship.
(1) 1 pairs of mu
the specified property of a persisted object (the persisted instance maps to the data row), the ORM is converted to the action that executes the data row, executes the column in the corresponding data table.Based on this basic mapping, ORM tools can accomplish the mapping between the object model and the relational model. Thus, in the ORM framework, the persistence object is an intermediary, the applicatio
, not-null= "True" indicates that a bid must have its corresponding item entity. The column property specifies that item_id columns in the T_bid table are a foreign key to the primary key of the T_item table.for bid, regardless of whether not-null= "true" is specified, its INSERT statement assigns a value to the item_id field, even if it is null. This is the cause of the exception, and this setting causes Hibernate to emit a similar insert into t_bid
individually through the session, or you will throw a mappingexception.The important difference between a value type and an entity type is that the former has no OID and cannot be persisted independently, and his life cycle relies on the life cycle of the object of the owning persisted class, which is a value type, and the entity type has an OID, which can be persisted independently.2. Mapping Composite Composition RelationshipFor example, Cpubox is
Relational mapping in Hibernate refers to the relationship between an entity class and an entity class. and the database table and the relationship between the table is similar to one-to-one, many pairs of a, a lot, many to more than four mapping relationship.
One: Mapping
Two objects are a one-to-ones relationship, a
Before giving you a detailed introduction to the three mapping methods of the Hibernate inheritance tree, let everyone know that the employee class is an abstract class, and then introduce it comprehensively.
In the domain model, in addition to association and aggregation relationships between classes and classes, there can also be inheritance relationships, a one-to-many two-way association between compan
Write a hibernate example fourth step: Test with JUnit
Three commonly used annotation labels
@Test: Test method@Before: Initialization method@After: Freeing ResourcesExecution order: Method under the Before Annotations tab under the method test annotation label method under after annotation label
Specific implementation steps: Source folder represents the directory of the original program, generally we put the test case under the source f
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.