欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
hibernate 動(dòng)態(tài)pojo Map
動(dòng)態(tài)domain,用一個(gè)Map來(lái)代替對像,把原來(lái)domain中的屬性做key值存進(jìn)來(lái) 
實(shí)體映射 
<hibernate-mapping> 
<class entity-name="ItemEntity" table="ITEM_ENTITY"> 
   <id name="id" type="long" column="ITEM_ID"> 
      <generator class="native"/> 
   </id> 
   <property name="initialPrice" 
       type="big_decimal" 
       column="INIT_PRICE"/> 
   <property name="description" 
       type="string" 
       column="DESCRIPTION"/> 
   <many-to-one name="seller" 
       entity-name="UserEntity" 
       column="USER_ID"/> 
        </class> 
<class entity-name="UserEntity" table="USER_ENTITY"> 
         <id name="id" type="long" column="USER_ID"> 
              <generator class="native"/> 
   </id> 
   <property name="username" 
        type="string" 
        column="USERNAME"/> 
   <bag name="itemsForSale" inverse="true" cascade="all"> 
       <key column="USER_ID"/> 
       <one-to-many entity-name="ItemEntity"/> 
   </bag> 
</class> 
</hibernate-mapping> 
注意: 
1.<class name="...">變?yōu)?lt;class entity-name="..."> 
2.<many-to-one>和<one-to-many> 中的class屬性變?yōu)閑ntity-name 

動(dòng)態(tài)domain的工作方式 
Map user = new HashMap(); 
user.put("username","davide"); 

Map item1 = new HashMap(); 
item1.put("description","an item for auction"); 
item1.put("initialPrice",new BigDecimal(99)); 
item1.put("seller",user); 

Map item2 = new HashMap(); 
item2.put("description", "Another item for auction"); 
item2.put("initialPrice", new BigDecimal(123)); 
item2.put("seller", user); 

Collection itemsForSale = new ArrayList(); 
itemsForSale.add(item1); 
itemsForSale.add(item2); 
user.put("itemsForSale", itemsForSale); 
session.save("UserEntity", user); 
第一個(gè)Map為UserEntity,接下來(lái)的兩個(gè)是ItemEntitys 
為兩個(gè)Map建立了seller user鏈接. 
一個(gè)Collection在inverse方設置one-to-many關(guān)聯(lián)初始化 

使用方法 
Long storedItemId = (Long) item1.get("id"); 
Map loadedItemMap = (Map) session.load("ItemEntity", storedItemId); 
loadedItemMap.put("initialPrice", new BigDecimal(100)); 

多次映射一個(gè)類(lèi) 
<hibernate-mapping> 
<class name="model.Item" 
        entity-name="ItemAuction" 
        table="ITEM_AUCTION"> 
   <id name="id" column="ITEM_AUCTION_ID">...</id> 
   <property name="description" column="DESCRIPTION"/> 
   <property name="initialPrice" column="INIT_PRICE"/> 
</class> 
<class name="model.Item" 
        entity-name="ItemSale" 
        table="ITEM_SALE"> 
   <id name="id" column="ITEM_SALE_ID">...</id> 
   <property name="description" column="DESCRIPTION"/> 
   <property name="salesPrice" column="SALES_PRICE"/> 
</class> 
</hibernate-mapping> 
model.Item持久化類(lèi)映射了id,description,initialPrice,salesPrice屬性. 
處決于你運行時(shí)的實(shí)體名,有些屬性是持久化的有的則不是. 
Item itemForAuction = new Item(); 
itemForAuction.setDescription("An item for auction"); 
itemForAuction.setInitialPrice( new BigDecimal(99) ); 
session.save("ItemAuction", itemForAuction); 

Item itemForSale = new Item(); 
itemForSale.setDescription("An item for sale"); 
itemForSale.setSalesPrice( new BigDecimal(123) ); 
session.save("ItemSale", itemForSale); 
正是由于有了邏輯名,hibernate才知道向哪個(gè)表中插入數據. 

將數據保存到xml文件 
Session dom4jSession = session.getSession(EntityMode.DOM4J); 
Element userXML = 
(Element) dom4jSession.load(User.class, storedUserId); 
可以通過(guò)以下方式打印到控件臺 
try { 
    OutputFormat format = OutputFormat.createPrettyPrint(); 
    XMLWriter writer = new XMLWriter( System.out, format); 
    writer.write( userXML ); 
} catch (IOException ex) { 
   throw new RuntimeException(ex); 
} 
若是繼續的前面的例子,你可能會(huì )得以下結果 
<User> 
   <id>1</id> 
   <username>johndoe</username> 
   <itemsForSale> 
     <Item> 
       <id>2</id> 
       <initialPrice>99</initialPrice> 
       <description>An item for auction</description> 
       <seller>1</seller> 
     </Item> 
     <Item> 
<id>3</id> 
<initialPrice>123</initialPrice> 
<description>Another item for auction</description> 
<seller>1</seller> 
     </Item> 
   </itemsForSale> 
</User> 
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
hibernate注解
多對多關(guān)聯(lián)映射(單向)
注解的力量 -----Spring 2.5 JPA hibernate 使用方法的點(diǎn)滴整理...
Hibernate注釋大全 2
5. ORM 基礎
Hibernate與Jpa的關(guān)系,終于弄懂
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久