我是休眠注释的新手。我有两张表 Merchant 和 MerchantDeal,我在这些表之间有一个外键。
当我尝试将数据插入 MerchantDeal 表时,正在创建另一列并且没有发生数据插入。
代码是:
Merchant
{
@Id
@Column(name="MERCHANT_ID")
private int iMerchantId;
@Column(name="MERCHANT_NAME")
private String sName;
@Column(name="MERCHANT_CODE")
private int iMerchantCode;
@Column(name="MERCHANT_URL")
private String sUrl;
@Column(name="MERCHANT_DESCRIPTION")
private String sDescription;
@Column(name="MERCHANT_LOGOURL")
private String sLogoUrl;
@Column(name="TERMS")
private String sTerms;
@Column(name="ACTIVE")
private boolean bIsActive;
@Column(name="MERCHANT_EXCLUSIVE")
private boolean bIsExclusive;
@Column(name="TERMS_CONDITIONS")
private String sTermsAndConditions;
@OneToMany(mappedBy="merchant")
private List<MerchantDeal> merchantDeals;
}
MerchantDeal
{
@Id
@Column(name="MERCHANTDEAL_ID")
@GeneratedValue
private int iMerchantDealId;
@OneToOne
@PrimaryKeyJoinColumn
private MerchantDealType oMerchantDealType;
@Column(name="MERCHANTDEAL_DESCRIPTION")
private String sDescription;
@Column(name="MERCHANTDEAL_URL")
private String sMerchantDealUrl;
@Column(name="MERCHANTDEAL_EXCLUSIVE")
private boolean bIsExclusive;
@Column(name="CASHBACKRATE")
private float fCashBackRate;
@Column(name="OFFERTITLE")
private String sOfferTitle;
@Column(name="WITHCASHBACK")
@Type(type="yes_no")
private boolean bIsWithCashBack;
@Column(name="PRINTABLE")
@Type(type="yes_no")
private boolean bIsPrintable;
@Column(name="VOUCHER_CODE")
private String sVoucherCode;
@Column(name="VALID_FROM")
private Date dValidFrom;
@Column(name="VALID_TO")
private Date dValidTo;
@Column(name="PRODUCT_ID")
private int iProductId;
@Column(name="PRODUCTIMAGE_URL")
private String sProductImageUrl;
@Column(name="TOSHOW")
@Type(type="yes_no")
private boolean bToShow;
@Column(name="DEALDELETED_DATE")
private Date dDealDeletedDate;
@ManyToOne
@MapsId
private Merchant merchant;
@Column(name="TERMS")
private String sTerms;
}
这是控制台:
31 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.1.0.GA
47 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: uk.co.wowcher.cashback.domain.beans.Merchant
78 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity uk.co.wowcher.cashback.domain.beans.Merchant on table CB_MERCHANT
109 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: uk.co.wowcher.cashback.domain.beans.MerchantDeal
109 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity uk.co.wowcher.cashback.domain.beans.MerchantDeal on table CB_MERCHANTDEAL
109 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: uk.co.wowcher.cashback.domain.beans.MerchantDealType
109 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity uk.co.wowcher.cashback.domain.beans.MerchantDealType on table CB_MERCHANTDEALTYPE
140 [main] INFO org.hibernate.cfg.annotations.CollectionBinder - Mapping collection: uk.co.wowcher.cashback.domain.beans.Merchant.merchantDeals -> CB_MERCHANTDEAL
140 [main] INFO org.hibernate.cfg.AnnotationConfiguration - Hibernate Validator not found: ignoring
May 16, 2013 7:39:58 PM org.springframework.orm.hibernate3.LocalSessionFactoryBean buildSessionFactory
INFO: Building new Hibernate SessionFactory
140 [main] INFO org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
May 16, 2013 7:39:58 PM org.hibernate.connection.ConnectionProviderFactory newConnectionProvider
INFO: Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Oracle, version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Oracle JDBC driver, version: 9.2.0.1.0
May 16, 2013 7:39:58 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.OracleDialect
May 16, 2013 7:39:58 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.springframework.orm.hibernate3.SpringTransactionFactory
May 16, 2013 7:39:58 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
May 16, 2013 7:39:58 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
May 16, 2013 7:39:58 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
May 16, 2013 7:39:58 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
May 16, 2013 7:39:58 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
May 16, 2013 7:39:58 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: Running hbm2ddl schema update
May 16, 2013 7:39:58 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: fetching database metadata
May 16, 2013 7:39:58 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: updating schema
May 16, 2013 7:39:58 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: TRAIN2.CB_MERCHANT
May 16, 2013 7:39:58 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [merchant_description, trackingstats_id, terms_conditions, merchant_name, terms, specialbonusavailabile, merchant_code, specialbonusavailability, merchant_url, merchant_logourl, active, specialbonus, merchant_id, merchant_exclusive]
May 16, 2013 7:39:58 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: [fk_trackingstats_id]
May 16, 2013 7:39:58 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [sys_c00311639]
May 16, 2013 7:39:59 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: TRAIN2.CB_MERCHANTDEAL
May 16, 2013 7:39:59 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [merchantdealtype_id, product_id, dealdeleted_date, valid_from, terms, merchantdeal_description, merchantdeal_id, printable, offertitle, voucher_code, productimage_url, cashbackrate, price_id, merchantdeal_url, merchantdeal_exclusive, cashbackratetype_id, merchant_id, toshow, withcashback, valid_to]
May 16, 2013 7:39:59 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: [fk_price_id, fk_cashbackratetype_id, fk_merchantdealtype_id, fk_merchant_id_10]
May 16, 2013 7:39:59 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [sys_c00311633]
May 16, 2013 7:39:59 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: TRAIN2.CB_MERCHANTDEALTYPE
May 16, 2013 7:39:59 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [merchantdealtype_id, merchantdealtype_name, merchantdealtype_description, merchantdealtype_code]
May 16, 2013 7:39:59 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: []
May 16, 2013 7:39:59 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [sys_c00311535]
May 16, 2013 7:39:59 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
谢谢。