I'm working on the database portion of a project which uses DeltaSpike and Hibernate in Java SE.
All SELECT statements work, however no INSERT statements appear in the database. There is no warning, error, or exception.
I've gone through the logs for Hibernate and found the following:
[DEBUG] [05/05 00:52:16] [org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl] JDBC transaction marked for rollback-only
I've tried adding the @Transactional annotation from javax.transaction and org.apache.deltaspike.jpa.api.transaction, as well as changing the autocommit setting in persistence.xml.
How can I get this to stop trying to roll back the transaction?
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2" 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">
<persistence-unit name="primary">
<properties>
<property name="hibernate.connection.autocommit" value="false"/>
<property name="hibernate.hbm2ddl.auto" value="validate"/>
<!-- Omitted for Brevity -->
</properties>
</persistence-unit>
</persistence>
ExampleRepository.java
@Repository(forEntity = ExampleData.class)
public interface ExampleRepository extends EntityRepository<ExampleData, Long> {
}
ExampleListener.java
@Singleton
public class ExampleListener extends ExampleAdapter {
private final ExampleRepository emoteRepo;
@Inject
public ExampleListener(ExampleRepository exampleRepo) {
this.exampleRepo = Objects.requireNonNull(exampleRepo);
}
@Override
public void onExample(ExampleEvent event) {
// Omitted for Brevity
ExampleData exampleData = new ExampleData(exampleId, parentId);
exampleRepo.save(exampleData);
}
}
}
The problem was that in the project,
@Entityand@Tablewere used incorrectly.The project had the following, but the queries generated were called
ExampleTable, notexamplewhich is what was intended.The solution was to change it too: