0

I keep table schema in this file tableaddress.orm.xml

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.1"
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <entity class="Address">
        <attributes>
            <basic name="city" attribute-type="String" />
            <basic name="country" attribute-type="int" />
            <basic name="province" attribute-type="double" />
            <basic name="postalCode" attribute-type="boolean">
            </basic>
            <basic name="street" attribute-type="String" />
        </attributes>
    </entity>
</entity-mappings>

Here is how I tried to create table using Hibernate

public class App 
{
    public static void main( String[] args )
    {

    Properties prop= new Properties();
    prop.setProperty("hibernate.connection.url", "jdbc:mariadb:......");
    prop.setProperty("dialect", "org.hibernate.dialect.MariaDB53Dialect");
    prop.setProperty("hibernate.connection.username", "user");
    prop.setProperty("hibernate.connection.password", "password");
    prop.setProperty("hibernate.connection.driver_class", "org.mariadb.jdbc.Driver");

     SessionFactory sessionFactory = new Configuration()
             .addResource("tableaddress.orm.xml").addProperties(prop).buildSessionFactory();
     Session session = sessionFactory.openSession();
     session.beginTransaction();
     session.getTransaction().commit();
     session.close(); 
    }
} 

It should work, there is no compile errors, but for some reason the table is not created

Error java.lang.NoClassDefFoundError: javax/transaction/SystemException

2
  • Wouldn’t you need to set the hibernate.hbm2ddl.auto property in the hibernate.cfg.xml ? See stackoverflow.com/questions/4507142/… Commented Jul 10, 2019 at 3:30
  • Getting the same error java.lang.NoClassDefFoundError: javax/transaction/SystemException Commented Jul 10, 2019 at 14:19

1 Answer 1

1

This is probably due to bug/feature in Hibernate.

The javax.transaction was removed from Hibernate (well, marked as "provided") in 5.0.4, but it was brought back in 5.0.7 (see https://hibernate.atlassian.net/browse/HHH-10307 :

"JTA no longer transitively provided (HHH-10178) causes problems for apps not using JTA"

)

So assuming you are using 5.04, 5.0.5 or 5.0.6, your choices are to either upgrade Hibernate, or to add the following dependency :

<dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>jta</artifactId>
    <version>1.1</version>
</dependency>
Sign up to request clarification or add additional context in comments.

5 Comments

Than you. But I'm using the latest version 5
Version 6 is beta
Ok, upgrading would have been good if you were in an older version. Still, adding the hat dependency will probably fix the issue, but shouldn’t be needed. Could you edit your question to include the hibernate and other database-related dependencies from your Pom ?
Thank you. That was the solution to NoClass error. However, it got replaced with a new error org.hibernate.AnnotationException: Unable to load class defined in XML: Address . I don't have a class Address . I only want to create a database table from xml file that's it. No classes. Should I open a new question and accept this one. Please let me know either way
I see that docs.jboss.org/hibernate/stable/annotations/reference/en/html/… section 3.1.2 says “An entity has to have a class attribute referring to the java class”, so unfortunately might not be possible - but that’s going outside my knowledge, so yes, new question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.