我曾经认为模式是数据库本身之前的"上层包装"对象.我的意思DB.schema.<what_ever_object_name_under_schema>.
那么,目录"包装器"现在非常令人困惑.我们为什么需要目录?出于何种目的,目前应该使用目录?
假设用户在单个主机上托管了两个数据库,我需要连接到它们,以便我可以随时使用任何表而无需多次添加连接代码.
我已经在CodeIgniter中实现了这一点,在database.php文件中添加了两个数据库的授权详细信息,并$this->load->database('dbname');在脚本中加载了所需的数据库.
现在,对于核心PHP,我们可以这样做:
mysql_connect ('host','user','password','port','dbname'); // connection with one database.
Run Code Online (Sandbox Code Playgroud)
它与我的第一个数据库连接.
现在,我想连接第二个数据库:
1)我没有关闭上面的连接并与第二个连接
mysql_connect ('host','user','password','port','dbname1');.
Run Code Online (Sandbox Code Playgroud)
2)这样做是不好的做法?它会消耗更多的物体吗?我们是否应该被要求先关闭第一个?
我对hibernates(版本5.1)命名策略感到有点困惑 - 即它改变了我的表名,我想避免这种情况.此外 - spring.jpa.hibernate.naming_strategy似乎根据intelij被弃用,但我找不到正确配置它的(另一种)方式.
我在application.properties中有以下配置:
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
spring.jpa.properties.hibernate.current_session_context_class=thread
Run Code Online (Sandbox Code Playgroud)
如上所述,第一个标记为已删除.
现在我有一个实体:
@Entity
@Table(name = "usaUploadTable", schema = "usertable201", catalog = "")
public class UsaUploadTable {
....
}
Run Code Online (Sandbox Code Playgroud)
表名称与@Table(name = "")usaUploadTable类似.
现在,当我运行我的应用程序时,我得到了
表'usertable201.usa_upload_table'不存在
这是正确的 - 它没有被命名为hibernate如何改变它.
我该怎么做才能让hibernate正确使用我的表名?
编辑:
我也试过了
DefaultNamingStrategy
ImprovedNamingStrategy
Run Code Online (Sandbox Code Playgroud)
所有这些都改变了它
版本:
spring-boot-1.4.0.RELEASE
hibernate 5.1
javax-transaction-api 1.2
hibernate-validator 5.2.4
javassist 3.20
Run Code Online (Sandbox Code Playgroud) 这是下面给出的程序的输出:
Connection made!
Schema Name:null
Successfully connected to null
Releasing all open resources ...
Run Code Online (Sandbox Code Playgroud)
在establishConnection()内,conn被初始化为null.然后try块中的第一个语句应该与数据库建立连接,然后第三个语句打印conn的当前模式的名称.
根据API,getSchema()返回当前模式名称,如果没有,则返回null.
这意味着没有与conn关联的模式(我认为模式名称与数据库名称相同)?任何人都可以建议我的预期是否正确,并且还建议为什么没有架构或与conn相关联的null?
public class ConnectDB {
private Connection establishConnection() throws SQLException {
Connection conn = null;
try {
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test_final1", "root", "password");
System.out.println("Connection made!");
System.out.println("Schema Name:"+conn.getSchema()+"\n");
} catch (SQLException sqle) {
System.err.println("SQL Exception thrown while making connection");
printSQLException(sqle);
}
return conn;
}
public static void main(String[] args) {
ConnectDB cdb= new ConnectDB();
Connection myconn=null;
try{
myconn=cdb.establishConnection();
if(myconn!=null) System.out.println("Successfully connected to …Run Code Online (Sandbox Code Playgroud) 小问题,我正在开发一个 saas 软件(erp)。
由于以下原因,我为每个帐户设计了 1 个数据库:
基本点:我正在转向拥有数百个数据库......
我正在聘请一家公司来管理我的服务器,他们说最好只有一个数据库,有几个表,并将所有数据放在同一个表中,列为id_account. 我对这些话感到非常惊讶,所以我想知道......你有什么想法?
谢谢 !
弗雷德里克
我已经了解到hibernate.hbm2ddl.auto创建Schema并执行其他各种操作。但在我的情况下,它不创建模式。我在我的本地主机上使用 MYSQL。它没有名为hibernate 的模式。我尝试了各种其他的东西,但仍然得到相同的Error。
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'hibernate'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Run Code Online (Sandbox Code Playgroud)
完全错误
Aug 06, 2018 5:31:48 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.12.Final}
Aug 06, 2018 5:31:48 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Aug 06, 2018 5:31:49 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Aug 06, 2018 5:31:49 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Aug 06, 2018 5:31:49 …Run Code Online (Sandbox Code Playgroud)