Hibernate进阶之路

Content

1.配置与SessionFactory

2.Mapping

2.1.Mapping File

2.2.Associations

2.2.1.Many-To-Many

2.2.2.One-To-Many

2.2.3.unidirectional link 和 bidirectional link

1.配置与SessionFactory

1.1.hibernate.cfg.xml

1.2.Programmatic配置

  • Configuration.addResource(),使用*.hbm.xml配置
    Configuration cfg = new Configuration()
    .addResource("Item.hbm.xml")
    .addResource("Bid.hbm.xml");
  • Configruration.addClass(),根据类名ClassName查找类所在包下的ClassName.hbm.xml
    Configuration cfg = new Configuration()
    .addClass(org.hibernate.auction.Item.class)
    .addClass(org.hibernate.auction.Bid.class);
  • Configuration.setProperty()
    Configuration cfg = new Configuration()
    .setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect")
    .setProperty("hibernate.connection.datasource", "java:comp/env/jdbc/test")
    .setProperty("hibernate.order_updates", "true");

    使用properties的方法:

    • 使用java.util.Properties作为参数调用Configuration.setProperties().
    • classpath的根目录下hibernate.properties文件
    • hibernate.cfg.xml中元素

2.Mapping

2.1.Mapping File

2.2.Associations

2.3.unidirectional link 和 bidirectional link

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s