我正在使用EclipseLink和Spring。
这是我的persistence.xml:
<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd" version="2.0">
<persistence-unit name="tpcw" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>eu.cloudscale.showcase.db.model.jpa.Address</class>
<class>eu.cloudscale.showcase.db.model.jpa.Author</class>
<class>eu.cloudscale.showcase.db.model.jpa.CcXacts</class>
<class>eu.cloudscale.showcase.db.model.jpa.Country</class>
<class>eu.cloudscale.showcase.db.model.jpa.Customer</class>
<class>eu.cloudscale.showcase.db.model.jpa.Item</class>
<class>eu.cloudscale.showcase.db.model.jpa.OrderLine</class>
<class>eu.cloudscale.showcase.db.model.jpa.Orders</class>
<class>eu.cloudscale.showcase.db.model.jpa.ShoppingCart</class>
<class>eu.cloudscale.showcase.db.model.jpa.ShoppingCartLine</class>
<class>eu.cloudscale.showcase.multiTenancy.model.SharedMetaData</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/tpcw"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="12345"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
<property name="eclipselink.weaving" value="false"/>
<property name="eclipselink.jdbc.allow-native-sql-queries" value="true"/>
</properties>
</persistence-unit>
</persistence>
这是我的spring-config-file.xml
<context:component-scan base-package="eu.cloudscale.showcase.db.dao.jpa.impl" />
<context:annotation-config/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method ="close">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="acquireIncrement" value="1" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="150" />
<property name="initialPoolSize" value="5" />
<property name="testConnectionOnCheckin" value="true" />
<property name="testConnectionOnCheckout" value="true" />
</bean>
<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="defaultDataSource" ref="dataSource" />
<property name="dataSources">
<map>
<entry>
<key>
<value>jdbc/__default</value>
</key>
<ref bean="dataSource" />
</entry>
<entry>
<key>
<value>jdbc/jta</value>
</key>
<ref bean="dataSource" />
</entry>
</map>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
</bean>
<bean id="service" class="eu.cloudscale.showcase.db.services.JPAService">
</bean>
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="tpcw" />
<property name="persistenceUnitManager" ref="persistenceUnitManager"/>
<property name="jpaDialect" ref="jpaDialect"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"/>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="true"/>
<property name="database" value="MYSQL"/>
</bean>
</beans>
除CcXacts和OrderLine外,所有表都已创建。 这是CcXacts实体类:
@Entity(name="cc_xacts")
@Table( name = "cc_xacts", catalog = "tpcw" )
@Multitenant(MultitenantType.SINGLE_TABLE)
@TenantDiscriminatorColumn(name = "TENANT_ID", primaryKey = true)
public class CcXacts implements ICcXacts, Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue( strategy = IDENTITY )
@Column( name = "CX_O_ID", unique = true, nullable = false, insertable = false, updatable = false)
private Integer id;
@ManyToOne( targetEntity=Orders.class, fetch = FetchType.LAZY )
@JoinColumns({
@JoinColumn( name = "CX_O_ID", referencedColumnName = "CX_O_ID", nullable = false),
@JoinColumn( name= "TENANT_ID", referencedColumnName = "TENANT_ID", nullable = false, insertable = false, updatable = false) })
private IOrders orders;
@Column( name = "CX_TYPE", length = 10 )
private String cxType;
@Column( name = "CX_CC_NUM" )
private Integer cxNum;
@Column( name = "CX_CC_NAME", length = 31 )
private String cxName;
@Temporal(TemporalType.DATE)
@Column( name = "CX_EXPIRY", length = 10 )
private Date cxExpiry;
@OneToOne( targetEntity=Author.class, fetch=FetchType.EAGER)
@JoinColumns({
@JoinColumn( name = "CX_AUTH_ID", referencedColumnName = "CX_AUTH_ID", nullable = false),
@JoinColumn( name= "TENANT_ID", referencedColumnName = "TENANT_ID", nullable = false, insertable = false, updatable = false) })
private IAuthor cxAuthId;
@Column( name = "CX_XACT_AMT", precision = 15)
private Double cxXactAmt;
@Column( name = "CX_XACT_DATE", length = 19)
@Temporal(TemporalType.DATE)
private Date cxXactDate;
@ManyToOne( targetEntity=Country.class, fetch = FetchType.LAZY )
@JoinColumns({
@JoinColumn( name = "CX_CO_ID", referencedColumnName = "CX_CO_ID", nullable = false),
@JoinColumn( name= "TENANT_ID", referencedColumnName = "TENANT_ID", nullable = false, insertable = false, updatable = false) })
private ICountry country;
@Override
public Integer getId()
{
return this.id;
}
@Override
public void setId(Integer string)
{
this.id = string;
}
@Override
public IOrders getOrders()
{
return this.orders;
}
@Override
public void setOrders(IOrders orders)
{
this.orders = orders;
}
@Override
public String getCxType()
{
return this.cxType;
}
@Override
public void setCxType(String cxType)
{
this.cxType = cxType;
}
@Override
public Integer getCxNum()
{
return this.cxNum;
}
@Override
public void setCxNum(Integer cxNum)
{
this.cxNum = cxNum;
}
@Override
public String getCxName()
{
return this.cxName;
}
@Override
public void setCxName(String cxName)
{
this.cxName = cxName;
}
@Override
public Date getCxExpiry()
{
return this.cxExpiry;
}
@Override
public void setCxExpiry(Date cxExpiry)
{
this.cxExpiry = cxExpiry;
}
@Override
public IAuthor getCxAuthId()
{
return this.cxAuthId;
}
@Override
public void setCxAuthId(IAuthor cxAuthId)
{
this.cxAuthId = cxAuthId;
}
@Override
public Double getCxXactAmt()
{
return this.cxXactAmt;
}
@Override
public void setCxXactAmt(Double o_TOTAL)
{
this.cxXactAmt = o_TOTAL;
}
@Override
public Date getCxXactDate()
{
return this.cxXactDate;
}
@Override
public void setCxXactDate(Date cxXactDate)
{
this.cxXactDate = cxXactDate;
}
@Override
public ICountry getCountry()
{
return this.country;
}
@Override
public void setCountry(ICountry country)
{
this.country = country;
}
}
这是OrderLine EntityClass:
@Entity(name="order_line")
@Table( name = "order_line", catalog = "tpcw" )
@Multitenant(MultitenantType.SINGLE_TABLE)
@TenantDiscriminatorColumn( name = "TENANT_ID", primaryKey = true)
public class OrderLine implements IOrderLine, Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue( strategy = IDENTITY )
@Column( name = "OL_ID")
private Integer id;
@ManyToOne( targetEntity=Orders.class, fetch = FetchType.EAGER )
@JoinColumns( {
@JoinColumn( name= "TENANT_ID", referencedColumnName ="TENANT_ID", nullable = false, insertable = false, updatable = false),
@JoinColumn( name = "OL_O_ID", referencedColumnName = "OL_O_ID", nullable = false, insertable = false, updatable = false)})
private IOrders orders;
@ManyToOne( targetEntity=Item.class, fetch = FetchType.EAGER )
@JoinColumns( {
@JoinColumn( name= "TENANT_ID", referencedColumnName ="TENANT_ID", nullable = false, insertable = false, updatable = false),
@JoinColumn( name = "OL_I_ID", referencedColumnName = "OL_I_ID", nullable = false, insertable = false, updatable = false)})
private IItem item;
@Column( name = "OL_QTY")
private Integer olQty;
@Column( name = "OL_DISCOUNT")
private Double olDiscount;
@Column( name = "OL_COMMENT", length = 100)
private String olComment;
public OrderLine()
{
}
public Integer getOlId()
{
return this.id;
}
public void setOlId(Integer olId)
{
this.id = olId;
}
public IOrders getOrders()
{
return this.orders;
}
public void setOrders(IOrders orders)
{
this.orders = orders;
}
public IItem getItem()
{
return this.item;
}
public void setItem(IItem item)
{
this.item = item;
}
public Integer getOlQty()
{
return this.olQty;
}
public void setOlQty(Integer olQty)
{
this.olQty = olQty;
}
public Double getOlDiscount()
{
return this.olDiscount;
}
public void setOlDiscount(Double oL_DISCOUNT)
{
this.olDiscount = oL_DISCOUNT;
}
public String getOlComment()
{
return this.olComment;
}
public void setOlComment(String olComment)
{
this.olComment = olComment;
}
}
有谁知道为什么没有创建表格?谢谢!