常用 annotation

 @DynamicInsert @DynamicUpdate   只对实体中值不为null的属性做更新
StockTransaction stockTran = new StockTransaction();
        //stockTran.setPriceOpen(new Float("1.2"));
        //stockTran.setPriceClose(new Float("1.1"));
        //stockTran.setPriceChange(new Float("10.0"));
        stockTran.setVolume(2000000L);
        stockTran.setDate(new Date());
        stockTran.setStock(stock);
 
        session.save(stockTran);

 dynamic-insert=false

INSERT 
    INTO
        mkyong.stock_transaction
        (DATE, PRICE_CHANGE, PRICE_CLOSE, PRICE_OPEN, STOCK_ID, VOLUME) 
    VALUES
        (?, ?, ?, ?, ?, ?)

dynamic-insert=true

Hibernate: 
    INSERT 
    INTO
        mkyong.stock_transaction
        (DATE, STOCK_ID, VOLUME) 
    VALUES
        (?, ?, ?)

 @JoinColumn

 @JoinColumn与@Column注释类似,区别是:@JoinColumn注释的是保存表与表之间关系的字段,它要标注在实体属性上,而@Column标注的是表中不包含表关系的字段




你可能感兴趣的:(常用 annotation)