Skip to content
Permalink
Browse files

Support for Hibernate DDL generation

  • Loading branch information...
Alex Stockinger
Alex Stockinger committed Sep 11, 2017
1 parent c9c8a86 commit 81e40432c40ba38594b0e038403eed67bbdb723d
@@ -76,7 +76,7 @@ private static Connection safe(final Connection connection) {
new Class<?>[]{Connection.class},
(proxy, method, args) -> {
try {
if (asList("close", "commit", "rollback").contains(method.getName())) {
if (asList("close", "commit", "rollback", "setAutoCommit").contains(method.getName())) {
return null;
}
return method.invoke(connection, args);
@@ -3,4 +3,8 @@ apply plugin: 'java'
dependencies {
compile project(":core-spi")
compile libHibernate

testCompile project(":junit4")
testCompile project(":h2")
testCompile libLogback
}
@@ -84,7 +84,7 @@ public void rollback() throws IllegalStateException, SecurityException, SystemEx

@Override
public void setRollbackOnly() throws IllegalStateException, SystemException {
throw new AssertionError("setRollbackOnly");
// Nothing to do
}

@Override
@@ -104,12 +104,12 @@ public void setTransactionTimeout(int seconds) throws SystemException {

@Override
public Transaction suspend() throws SystemException {
throw new AssertionError("Suspend");
return transaction();
}

@Override
public void resume(Transaction tobj) throws InvalidTransactionException, IllegalStateException, SystemException {
throw new AssertionError("Resume");
// nothing to do
}
};
}
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2017 Alex Stockinger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fi.testee.hibernate;

import fi.testee.h2.H2PostgresConnectionFactory;
import fi.testee.jdbc.TestData;
import fi.testee.jdbc.TestDataSource;
import fi.testee.jpa.TestPersistenceUnits;
import fi.testee.junit4.TestEEfi;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@RunWith(TestEEfi.class)
@TestDataSource(name = "jdbc/test", factory = H2PostgresConnectionFactory.class)
public class HibernateTest {
@PersistenceContext(unitName = "hibernate")
private EntityManager em;

@TestData
public static void setupTestData(final TestPersistenceUnits units) {
units.get("hibernate").persist(new TestEntity(1));
}

@Test
public void runTest() {
em.find(TestEntity.class, 1);
}
}
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2017 Alex Stockinger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fi.testee.hibernate;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class TestEntity {
@Id
private int id;

public TestEntity() {
}

public TestEntity(final int id) {
this.id = id;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}
}
@@ -0,0 +1,14 @@
<?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="hibernate" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>jdbc/test</jta-data-source>

<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>

0 comments on commit 81e4043

Please sign in to comment.
You can’t perform that action at this time.