I am new to Play Framework and I am trying to do a simple example to understand how it works. I have used the template play-spring-data-jpa to start. I would like to use MySQL in a persistent way and that is why I chose it.
I started with h2 to understand how it works and then tried to move to connecting to a MySQL local database.
I followed the steps to use JPA from https://www.playframework.com/documentation/2.1.0/JavaJPA to get a persistence unit.
The code works fine with h2, but when I switch to MySQL, I get an error.
The connection with the database works fine, as I get the message:
[info] play - database [default] connected at jdbc:mysql://localhost/brainUp?useUnicode=yes&characterEncoding=UTF-8&connectionCollation=utf8_general_ci
But right after that message I get the following one:
[error] o.h.t.h.SchemaUpdate - could not get database metadata
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table 'sequences' in information_schema
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_51]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_51]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_51]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_51]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[mysql-connector-java-5.1.18.jar:na]
at com.mysql.jdbc.Util.getInstance(Util.java:386) ~[mysql-connector-java-5.1.18.jar:na]
[error] o.h.t.h.SchemaUpdate - could not complete schema update
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table 'sequences' in information_schema
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_51]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_51]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_51]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_51]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[mysql-connector-java-5.1.18.jar:na]
at com.mysql.jdbc.Util.getInstance(Util.java:386) ~[mysql-connector-java-5.1.18.jar:na]
I don't quite understand the message and I have been searching for quite long and have not found anything that makes me understand what is happening.
Thanks in advance
Thank you #Krzysiek for the interest. I revised the persistence.xml again and found the error there. As I think you suspected it was about the defined dialect.
As I previously used h2, so the dialect was defined for that instead of for MySQL.
Here's the new persistence.xml which works fine, in case someone encounters the same problem as me.
<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="default" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
I also would like to note for new users like me that if you want to create the tables from java code you should set to create-drop, and just to use and edit data stored you might want to switch it to "update" instead, when the database is created and will not suffer structural changes anymore.
Related
I get the error below when deploying the app to Wildfly:
{"WFLYCTL0080: Failed services" => {"jboss.persistenceunit."funmusic-back.war#productPU"" => "jakarta.persistence.PersistenceException: [PersistenceUnit: productPU] Unable to build Hibernate SessionFactory
Caused by: jakarta.persistence.PersistenceException: [PersistenceUnit: productPU] Unable to build Hibernate SessionFactory
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Unable to open specified script target file for writing : productDrop.ddl
Caused by: java.io.FileNotFoundException: productDrop.ddl (Permission denied)"}}
The tricky point I met is, when I start the wildfly by standalone.sh, it is alright. However, when I start it using systemctl start wildfly, this problem happen. I am wondering whether it is the problem related to the Domain Mode and Standalone Mode of Wildfly, but could not recognize the missing piece I should learn in order to solve the problem. My OS using is CentOS 7 and the Wildfly version is 25.
Below is the persistence.xml for your reference:
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
version="2.2">
<!-- transaction-type is the type of transactions used by EntityManagers from this persistence unit. -->
<persistence-unit name="productPU" transaction-type="JTA">
<properties>
<property name ="javax.persistence.schema-generation.database.action" value="drop-and-create"></property>
<property name ="javax.persistence.schema-generation.scripts.action" value="drop-and-create"></property>
<property name ="javax.persistence.schema-generation.scripts.create-target" value="productCreate.ddl"></property>
<property name ="javax.persistence.schema-generation.scripts.drop-target" value="productDrop.ddl"></property>
</properties>
</persistence-unit>
I get a single #Entity which is a very simple POJO with a few fields within. As it is simple, I am going to skip it here.
It would be grateful if you could point out the cause of the problem and give me some insight of it. Also, document reference with section specified would be more appreciated.
Thank you!
I'm making a Java program that connects to an SQL Server database together with a small team. Their code runs succesfully, but whenever I try to launch the Java application, I get the error: Cannot open database "Taijitan" requested by the login. The login failed. ClientConnectionId:f96fe50c-768a-4e85-8673-3e39a8feb1e4
I already checked my TCP/IP in SQL Server Management / Configuration.
In the netbeans.conf file I changed the JDKhome to jdk10.0.2.
In the env var I added the path to jdk10.0.2.
I also added the sqljdbc_auth.dll file to programfiles/java/jdk10.0.2/lib and also to bin. In SQL Server Manager I also checked if my Windows account has all the required permissions.
Persistence unit
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="TaijitanPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>domein.Persoon</class>
<class>domein.Graad</class>
<class>domein.Locatie</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://localhost\sqlexpress:1433;databaseName=Taijitan;integratedSecurity=true;"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>
Error message
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open database "Taijitan" requested by the login. The login failed. ClientConnectionId:f96fe50c-768a-4e85-8673-3e39a8feb1e4
Error Code: 4060
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:473)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:372)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:941)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.ExceptionInInitializerError
at persistentie.PersistentieController.<init>(PersistentieController.java:18)
at domein.Club.<init>(Club.java:16)
at domein.DomeinController.<init>(DomeinController.java:14)
at startup.Main.start(Main.java:29)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
... 1 more
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.3.v20180807-4be1041): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open database "Taijitan" requested by the login. The login failed. ClientConnectionId:f96fe50c-768a-4e85-8673-3e39a8feb1e4
Error Code: 4060
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:852)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:219)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:197)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getDatabaseSession(EntityManagerFactoryImpl.java:542)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:153)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:191)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:78)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at persistentie.GenericDaoJpa.<clinit>(GenericDaoJpa.java:10)
... 13 more
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.3.v20180807-4be1041): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open database "Taijitan" requested by the login. The login failed. ClientConnectionId:f96fe50c-768a-4e85-8673-3e39a8feb1e4
Error Code: 4060
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:328)
at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:140)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:172)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:233)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:815)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:256)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:767)
... 21 more
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open database "Taijitan" requested by the login. The login failed. ClientConnectionId:f96fe50c-768a-4e85-8673-3e39a8feb1e4
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:254)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:258)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:104)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$1LogonProcessor.complete(SQLServerConnection.java:4488)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:4773)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3581)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:81)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3541)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7240)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2869)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2395)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2042)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1889)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1120)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:700)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:189)
at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:100)
... 26 more
Exception running application startup.Main
Java Result: 1
I'm developing Hibernate JPA persistance web application, with my persistence.xml in src/main/resources/META-INF/persistence.xml (in war file it's in WEB-INF/classes/META-INF). It all works well on local Tomcat server, but when put on Openshift JBoss EWS, getting this message on startup:
Caused by: javax.persistence.PersistenceException: Unable to locate persistence units
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:101)
at org.hibernate.ejb.HibernatePersistence.getEntityManagerFactoryBuilderOrNull(HibernatePersistence.java:93)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:88)
at org.hibernate.ejb.HibernatePersistence.getEntityManagerFactoryBuilderOrNull(HibernatePersistence.java:101)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:69)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at komante.server.SpringConfig.devEntityManagerFactory(SpringConfig.java:29)
at komante.server.SpringConfig$$EnhancerBySpringCGLIB$$17e4a4c6.CGLIB$devEntityManagerFactory$1()
at komante.server.SpringConfig$$EnhancerBySpringCGLIB$$17e4a4c6$$FastClassBySpringCGLIB$$55fcba01.invoke()
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
at komante.server.SpringConfig$$EnhancerBySpringCGLIB$$17e4a4c6.devEntityManagerFactory()
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
... 28 more
Caused by: java.util.MissingResourceException: Could not load any resource bundle by com.sun.org.apache.xerces.internal.impl.msg.XMLSchemaMessages
at com.sun.org.apache.xerces.internal.utils.SecuritySupport$7.run(SecuritySupport.java:174)
at com.sun.org.apache.xerces.internal.utils.SecuritySupport$7.run(SecuritySupport.java:166)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.org.apache.xerces.internal.utils.SecuritySupport.getResourceBundle(SecuritySupport.java:166)
at com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter.formatMessage(XSMessageFormatter.java:70)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:398)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(XSDHandler.java:4162)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaError(XSDHandler.java:4145)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDAbstractTraverser.reportSchemaError(XSDAbstractTraverser.java:721)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDSimpleTypeTraverser.getSimpleType(XSDSimpleTypeTraverser.java:406)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDSimpleTypeTraverser.traverseSimpleTypeDecl(XSDSimpleTypeTraverser.java:163)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDSimpleTypeTraverser.traverseGlobal(XSDSimpleTypeTraverser.java:104)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.traverseSchemas(XSDHandler.java:1442)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:630)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:617)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:575)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:541)
at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema(XMLSchemaFactory.java:252)
at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:627)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.resolveLocalSchema(PersistenceXmlParser.java:435)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.v21Schema(PersistenceXmlParser.java:400)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.validate(PersistenceXmlParser.java:347)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.loadUrl(PersistenceXmlParser.java:310)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.parsePersistenceXml(PersistenceXmlParser.java:114)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.doResolve(PersistenceXmlParser.java:104)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.locatePersistenceUnits(PersistenceXmlParser.java:86)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:97)
Persistence.xml starts with
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
and has two persistence units in it. I alse deleted hibernate.cfg.xml, both things suggested in other SO answers. Anyone know what I'm doing wrong here?
Got it.
The problem was I used Persistence.createEntityManagerFactory("unit") to create EntityManagerFactory and injected it in other Spring beans.
Now I put
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="unit" />
</bean>
directly in applicationContext.xml.
Still doesn't explain what was wrong with previous approach, but it works.
My setup is hibernate / JPA using hsqldb for doing integration tests. I would like to be able to use a sql script to populate some test data into the database.
Essentially I'm looking for an equivalent of Spring's
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="classpath:test-data-hsql.sql"/>
</jdbc:initialize-database>
Except for this project using Spring is not an option for me. I've read various hsql articles suggesting this is possible using file mode and pointing the path at the script but I haven't been able to get this working.
My persistence.xml
<persistence-unit name="test-pu" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>...</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"></property>
<property name="hibernate.connection.username" value="sa"></property>
<property name="hibernate.connection.password" value=""></property>
<property name="hibernate.connection.url" value="jdbc:hsqldb:file:test-data-hsql"></property>
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"></property>
<property name="hibernate.hbm2ddl.auto" value="create"></property>
<property name="hibernate.show_sql" value="true"></property>
</properties>
</persistence-unit>
The test-data-hsql.script does get run but there is always an error.
If I include the DDL statements in the script to create I get
Caused by: org.hsqldb.HsqlException: invalid schema name: INFORMATION_SCHEMA
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.SchemaManager.getUserSchemaHsqlName(Unknown Source)
at org.hsqldb.StatementSchema.getResult(Unknown Source)
at org.hsqldb.StatementSchema.execute(Unknown Source)
at org.hsqldb.Session.executeCompiledStatement(Unknown Source)
If I exclude the DDL statements (hoping I can rely on hbm2ddl.auto = create) then I get
Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: INFORMATION_SCHEMA.ONETESTUSER
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.SchemaManager.getUserTable(Unknown Source)
at org.hsqldb.scriptio.ScriptReaderText.processStatement(Unknown Source)
at org.hsqldb.scriptio.ScriptReaderText.readLoggedStatement(Unknown Source)
at org.hsqldb.scriptio.ScriptReaderText.readDDL(Unknown Source)
at org.hsqldb.scriptio.ScriptReaderBase.readAll(Unknown Source)
at org.hsqldb.persist.Log.processScript(Unknown Source)
at org.hsqldb.persist.Log.open(Unknown Source)
at org.hsqldb.persist.Logger.open(Unknown Source)
at org.hsqldb.Database.reopen(Unknown Source)
at org.hsqldb.Database.open(Unknown Source)
at org.hsqldb.DatabaseManager.getDatabase(Unknown Source)
Does anyone have an example with a working script file or a better way to do this? I'm not necessarily tied to hsqldb if there is an alternative that can support this feature.
Update
The Minimal Script I am using to produce the error has no reference to INFORMATION_SCHEMA
drop table AccessToken if exists
create table AccessToken (id integer generated by default as identity (start with 1), createdAt timestamp not null, lastAccessedAt timestamp, token varchar(255) not null, expirationPolicyId varchar(255) not null, userId varchar(255) not null, primary key (id))
insert into ACCESSTOKEN (id, createdAt, lastAccessedAt, token, expirationPolicyId, userId) values (1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'welcome1', 'oneDayPolicy', 'jtrotter');
You need the DDL statements in the script, otherwise the database is empty and you get the second error.
The problem is in the script, is has reference for mySQL specific meta data schema INFORMATION_SCHEMA. Remove reference to objects in that schema so that the create tables can complete.
My team and me are currently working at a project using Hibernate-Validation and JPA.
Problem: we decided to use "drop-and-create-table" during the development-phase. everything worked just fine and as everything was implemented we changed the generation-mode to "none" (with a stable database running).
What it was doing before: We drop the table, create the table from our entities with specific attributes and fill the table with some datasets.
What it is doing now: We work on the existing, previously working, table (already filled with some data); but now some relations seem to be missing.
Now we have encountered a number of Exceptions during runtime and we can't locate them. It seems, that some attribute-relationships were deleted or something, because there are Exceptions (e.g. NullPointerExceptions) thrown, that were not thrown before.
Is there anything else we have to change in the persistence.xml, except the generation-mode?
here's the code for the persistance.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="ticketline" transaction-type="RESOURCE_LOCAL">
<class>at.ticketline.entity.Veranstaltung</class>
<class>at.ticketline.entity.Saal</class>
<class>at.ticketline.entity.Reihe</class>
<class>at.ticketline.entity.Platz</class>
<class>at.ticketline.entity.Person</class>
<class>at.ticketline.entity.Ort</class>
<class>at.ticketline.entity.News</class>
<class>at.ticketline.entity.Kunde</class>
<class>at.ticketline.entity.Kuenstler</class>
<class>at.ticketline.entity.Kategorie</class>
<class>at.ticketline.entity.Bestellung</class>
<class>at.ticketline.entity.BestellPosition</class>
<class>at.ticketline.entity.BaseEntity</class>
<class>at.ticketline.entity.Auffuehrung</class>
<class>at.ticketline.entity.Artikel</class>
<class>at.ticketline.entity.Adresse</class>
<class>at.ticketline.entity.Benutzer</class>
<class>at.ticketline.entity.Ticket</class>
<class>at.ticketline.entity.compositekeys.PlatzPK</class>
<class>at.ticketline.entity.compositekeys.ReihePK</class>
<class>at.ticketline.entity.compositekeys.SaalPK</class>
<class>at.ticketline.entity.compositekeys.AuffuehrungPK</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:hsql://localhost/ticketline" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="eclipselink.ddl-generation" value="none" />
</properties>
</persistence-unit>
</persistence>
Stack-Trace:
!STACK 0
java.lang.NullPointerException
at at.ticketline.kassa.ui.editor.TicketSuchergebnisEditor$11.getText(TicketSuchergebnisEditor.java:253)
at org.eclipse.jface.viewers.ColumnLabelProvider.update(ColumnLabelProvider.java:36)
at org.eclipse.jface.viewers.ViewerColumn.refresh(ViewerColumn.java:152)
at org.eclipse.jface.viewers.AbstractTableViewer.doUpdateItem(AbstractTableViewer.java:399)
at org.eclipse.jface.viewers.StructuredViewer$UpdateItemSafeRunnable.run(StructuredViewer.java:485)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.StructuredViewer.updateItem(StructuredViewer.java:2167)
at org.eclipse.jface.viewers.AbstractTableViewer.createItem(AbstractTableViewer.java:277)
at org.eclipse.jface.viewers.AbstractTableViewer.internalRefreshAll(AbstractTableViewer.java:757)
at org.eclipse.jface.viewers.AbstractTableViewer.internalRefresh(AbstractTableViewer.java:649)
at org.eclipse.jface.viewers.AbstractTableViewer.internalRefresh(AbstractTableViewer.java:636)
at org.eclipse.jface.viewers.AbstractTableViewer$2.run(AbstractTableViewer.java:592)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1443)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1404)
at org.eclipse.jface.viewers.AbstractTableViewer.inputChanged(AbstractTableViewer.java:590)
at org.eclipse.jface.viewers.ContentViewer.setInput(ContentViewer.java:280)
at org.eclipse.jface.viewers.StructuredViewer.setInput(StructuredViewer.java:1690)
at at.ticketline.kassa.ui.editor.TicketSuchergebnisEditor.createPartControl(TicketSuchergebnisEditor.java:67)
at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:670)
at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:465)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:313)
at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:180)
at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:270)
at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:473)
at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1245)
at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1198)
at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1597)
at org.eclipse.ui.internal.PartStack.add(PartStack.java:493)
at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:103)
at org.eclipse.ui.internal.PartStack.add(PartStack.java:479)
at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:112)
at org.eclipse.ui.internal.EditorSashContainer.addEditor(EditorSashContainer.java:63)
at org.eclipse.ui.internal.EditorAreaHelper.addToLayout(EditorAreaHelper.java:225)
at org.eclipse.ui.internal.EditorAreaHelper.addEditor(EditorAreaHelper.java:213)
at org.eclipse.ui.internal.EditorManager.createEditorTab(EditorManager.java:808)
at org.eclipse.ui.internal.EditorManager.openEditorFromDescriptor(EditorManager.java:707)
at org.eclipse.ui.internal.EditorManager.openEditor(EditorManager.java:666)
at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched(WorkbenchPage.java:2942)
at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:2850)
at org.eclipse.ui.internal.WorkbenchPage.access$11(WorkbenchPage.java:2842)
at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:2793)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2789)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2773)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2756)
at at.ticketline.kassa.ui.command.TicketSucheResultsCommandHandler.execute(TicketSucheResultsCommandHandler.java:28)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:293)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:178)
at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:247)
at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:247)
at at.ticketline.kassa.ui.view.TicketSucheView.openEditor(TicketSucheView.java:246)
at at.ticketline.kassa.ui.view.TicketSucheView$1.widgetSelected(TicketSucheView.java:194)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at at.ticketline.kassa.TicketlineApplication.start(TicketlineApplication.java:21)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
My guess is that your database is missing some data.
When you run your populate in memory, you are populating the shared cache and the database. However you are most likely no building your objects correctly.
Maybe you have transient fields that you set in memory, but when you read from the database, these transient fields are null.
Maybe you have bi-directional relationships and are not setting both sides of the relationships, so are not populating the database correctly.
Maybe you have not mapped some attributes correctly, so the data in the database is not correct.
My guess is that if you disabled the shared cache, you would have the same errors.