Простое локальное приложение JPA2HBase с DataNucleus

Я хочу создать минималистичное локальное приложение, которое читает/записывает HBase через JPA2 без orm.xml и без maven2. Таким образом, я использую Eclipse с плагином DataNucleus, чей Enhancer включен для проекта.

На основе http://matthiaswessendorf.wordpress.com/2010/03/17/apache-hadoop-hbase-plays-nice-with-jpa/ Я получил следующие сущности:

@Entity
@Table(name="account_table")
public class Account
{

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private String id;

    String firstName = null;
    String lastName = null;
    int level = 0;
    @Embedded
    Login login = null;

    public Account() {      }

    public Account(String firstName, String lastName, int level, Login login) {
        super();
        this.firstName = firstName;
        this.lastName = lastName;
        this.level = level;
        this.login = login;
    }

а также

@Embeddable
public class Login
{

    private String login = null;
    private String password = null;

    public Login() {
        // TODO Auto-generated constructor stub
    }

    public Login(String login, String password) {
        super();
        this.login = login;
        this.password = password;
    }
 }

src/META-INF/persistence.xml

<persistence
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">
    −
    <persistence-unit name="hbase-addressbook"
        transaction-type="RESOURCE_LOCAL">
        <class>de.syrtec.jpa2hbase.entities.Login</class>
        <class>de.syrtec.jpa2hbase.entities.Account</class>

        <properties>
            <property name="datanucleus.ConnectionURL" value="hbase" />
            <property name="datanucleus.ConnectionUserName" value="" />
            <property name="datanucleus.ConnectionPassword" value="" />
            <property name="datanucleus.autoCreateSchema" value="true" />
            <property name="datanucleus.validateTables" value="false" />
            <property name="datanucleus.Optimistic" value="false" />
            <property name="datanucleus.validateConstraints" value="false" />
        </properties>
    </persistence-unit>
</persistence>

ДАО:

public class TestDAO {
    public static void main(String[] args) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("hbase-addressbook");
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = null;

        Account a1 = new Account("myPre", "mySur", 1, new Login("a", "b"));

        tx = em.getTransaction();
        tx.begin(); 
            em.persist(a1);
        tx.commit();
    }
}

Но когда выполняется первая строка тестового DAO...

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("hbase-addressbook");

..Я получил:

11/09/01 06:57:05 INFO DataNucleus.MetaData: Class "de.syrtec.jpa2hbase.entities.Account" has been specified with JPA annotations so using those.
11/09/01 06:57:05 INFO DataNucleus.MetaData: Class "de.syrtec.jpa2hbase.entities.Login" has been specified with JPA annotations so using those.
Exception in thread "main" javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "hbase-addressbook" after trying the following discovered implementations: org.datanucleus.api.jpa.PersistenceProviderImpl from provider: org.datanucleus.api.jpa.PersistenceProviderImpl
    at javax.persistence.Persistence.createPersistenceException(Persistence.java:242)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:184)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:70)
    at de.syrtec.jpa2hbase.start.TestDAO.main(TestDAO.java:15)
Caused by: org.datanucleus.exceptions.NucleusUserException: Errors were encountered when loading the MetaData for the persistence-unit "hbase-addressbook". See the nested exceptions for details
    at org.datanucleus.metadata.MetaDataManager.loadPersistenceUnit(MetaDataManager.java:879)
    at org.datanucleus.api.jpa.JPAEntityManagerFactory.initialiseNucleusContext(JPAEntityManagerFactory.java:745)
    at org.datanucleus.api.jpa.JPAEntityManagerFactory.<init>(JPAEntityManagerFactory.java:422)
    at org.datanucleus.api.jpa.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:91)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:150)
    ... 2 more
Caused by: org.datanucleus.exceptions.ClassNotResolvedException: Class "−

        de.syrtec.jpa2hbase.entities.Login" was not found in the CLASSPATH. Please check your specification and your CLASSPATH.
    at org.datanucleus.JDOClassLoaderResolver.classForName(JDOClassLoaderResolver.java:247)
    at org.datanucleus.JDOClassLoaderResolver.classForName(JDOClassLoaderResolver.java:412)
    at org.datanucleus.metadata.MetaDataManager.loadPersistenceUnit(MetaDataManager.java:859)
    ... 6 more

Прежде чем я запустил DAO, я успешно активировал расширение класса с помощью datanucleus:

DataNucleus Enhancer (version 3.0.0.release) : Enhancement of classes
DataNucleus Enhancer completed with success for 2 classes. Timings : input=623 ms, enhance=101 ms, total=724 ms. Consult the log for full details

Хотя я не понимаю, что улучшение не запускается автоматически (ссылаясь на журналы), несмотря на то, что автоматическое улучшение для проекта активировано.

Кто-нибудь знает, почему мои сущности не найдены?


person Christian Schäfer    schedule 01.09.2011    source источник


Ответы (1)


И этот минус в файле persistence.xml?

person DataNucleus    schedule 02.09.2011
comment
Решение проблемы было СЛИШКОМ простым... коллега посоветовал мне удалить явный список классов в файле persistence.xml... и тата... это работает :) @DataNucleus: Интересно, откуда взялся этот минус. ..удалил его, чтобы предотвратить дальнейшие проблемы - person Christian Schäfer; 02.09.2011