Hibernate 3 Formulas
Pages: 1, 2, 3, 4
one-to-one
In Hibernate, one-to-one is mainly used for two
tables sharing the same primary key. For foreign key association,
we normally use many-to-one instead. However, with
formula, one-to-one is able to link up
tables via a foreign key. The above many-to-one
example can be mapped by one-to-one as follows:
<hibernate-mapping>
<class name="Company" table="Company" >
<id name="id" />
<one-to-one name="defaultContactPerson"
property-ref="defaultContactPerson" >
<formula>id</formula>
<formula>1</formula>
</many-to-one>
</class>
<class name="Person" >
<id name="id" />
<properties name="defaultContactPerson">
<property name="companyID" />
<property name="defaultFlag" />
</properties>
</class>
</hibernate-mapping>
Others: many-to-many
formula can be used with a
many-to-many element for a special joining from
relationship table to an entity table, although this is not often
needed.
Summary
The examples in this article show most of the
formula usage scenarios. When a formula
evaluation value is needed, the formula expression
will appear in the select part of the resulting SQL
statement. And when a formula is used for joining, it
appears in the where part of the resulting SQL statement.
Furthermore, a formula expression can use any dialect
of SQL, as long as the target database can support it. As a result,
formula helps achieve fine-grained mapping from data
model to object model without code.
Resources
- Sample code for this article.
- Hibernate provides most information about Hibernate ORM.
- Filter Article on TheServerSide for external filter introduction.
- Spring is a very friendly framework and provides integration with Hibernate and other data access tools.
- "Dependency Injection:" A definitive introduction of dependency injection.
- Dependency Injection Basics: An easy-to-understand introduction of dependency injection.
Dai Yifan is a technical consultant for a leading banking solution provider
Return to ONJava.com.
-
Map (Many-to-Many)
2006-09-22 11:53:44 Silvina [View]
-
good job
2006-09-15 08:43:25 HongLi [View]
- Trackback from http://210.183.205.6/tobyconfluence/display/Hibernate/Home
Home
2005-10-31 00:30:10 [View]
- Trackback from http://210.183.205.6/tobyconfluence/display/Hibernate/Home
Home
2005-10-20 17:49:14 [View]
- Trackback from http://java.mblogger.cn/play100/story/19146.aspx
Hibernate-formula
2005-10-07 23:03:19 [View]
- Trackback from http://java.mblogger.cn/play100/story/19146.aspx
Hibernate-formula
2005-10-07 23:02:17 [View]
- Trackback from http://gleamynode.net/wordpress/?p=69
Hibernate 3 Formulas
2005-08-10 23:27:42 [View]
-
A typo error in one-to-one example.
2005-08-10 23:19:38 trustin [View]