我正在尝试在Microsoft SQL Server 2012上的数据库中从Java自动创建表。我正在使用JPA并且有我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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 http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="PU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>DS</jta-data-source>
<class>msg.Message</class>
<class>msg.Response</class>
<properties>
<property name="hibernate.connection.driver_class" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
</properties>
</persistence-unit>
glassfish上的JDBC连接池ping成功(其他属性
URL:jdbc:sqlserver://127.0.0.1; databaseName = test; instanceName = SQLEXPRESS; 用户:用户 密码:密码 PortNumber:1433)
Message.java的标题
@Entity
@Table(name = "message", schema = "xxx_msg")
public class Message implements Serializable {
@Id
@Basic(optional = false)
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Integer id;
@JoinColumn(name = "sender_id", referencedColumnName = "id")
@ManyToOne
private Person senderId;
构建或部署时没有错误,数据库已启动但未创建表
答案 0 :(得分:0)
固定
我必须首先使用Microsoft SQL Server Management Studio创建模式(我的数据库 - &gt;新查询 - &gt; CREATE SCHEMA xxx_msg)