java - JBoss EAP 不在指定数据库上生成表
问题描述
我在尝试使用 JBoss EAP 7.2 生成表时遇到问题。
我的数据库在 MS SQL 2014 上被命名为 KMT,但是当我运行 JBoss EAP 时,尽管我在连接 URL 中指定了 KMT,但它会在名为“master”的系统数据库中创建表。
我使用 JBoss EAP 的管理控制台创建了数据源,在测试连接时我收到了一条成功消息。
我的连接网址:
JNDI Name: java:/MSSQLDS
Driver Name: sqljdbc42.jar
Connection URL: jdbc:microsoft:sqlserver://localhost:1433;databasename=KMT
我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="KMT">
<jta-data-source>java:/MSSQLDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
最后是我尝试在 KMT 数据库中生成的实体:
package be.Alstom.kmt.domaine;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
@SuppressWarnings("serial")
@Entity
@Table(name="designer", schema="kmt")
public class Designer implements Serializable{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
@Column
@NotNull
private String userName;
@Column
@NotNull
private String password;
public Designer() {
}
public Designer(String userName, String password) {
super();
this.userName = userName;
this.password = password;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result + ((password == null) ? 0 : password.hashCode());
result = prime * result + ((userName == null) ? 0 : userName.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Designer other = (Designer) obj;
if (id != other.id)
return false;
if (password == null) {
if (other.password != null)
return false;
} else if (!password.equals(other.password))
return false;
if (userName == null) {
if (other.userName != null)
return false;
} else if (!userName.equals(other.userName))
return false;
return true;
}
}
这里是我的 MSSQL 服务器。Hibernate 在 systemdatabase/master 而不是 KMT 中创建表。
解决方案
推荐阅读
- postgresql - Postgresql 查询性能优化
- javascript - Photoswipe 打开没有动画的幻灯片,但仅在第一次单击时打开
- powerbi - 使用警报创建带有选择条件的过滤器
- django - 在 DRF 中实现可以读取 request.data 的自定义身份验证
- c++ - 预定义 C++ 类型(编译器内部)未找到错误
- python - Django:在不同应用程序的html文件之间传递上下文数据
- javascript - 如何禁用按钮上的链接但是当我点击卡片链接时应该可以工作
- linux - Beyond Linux From Scratch:avrdude 是在没有 USB 支持的情况下编译的
- python-3.x - AttributeError:“超级”对象没有属性“word_weighting”
- python-3.x - 准备两个并行的 LSTM 模型并将结果馈送到 Keras 建模中的第三个模型