iljabauer / quamo-wiki

2 stars 0 forks source link

Integrate HEDL into the metricprocessor prototype #25

Closed pp23 closed 9 years ago

pp23 commented 9 years ago

This works even with Maven, but there is a hibernate based exception thrown. Do you know a quick fix for it? In my last implementation using jpa.data I put the db configuration into the application.properties file.

javax.persistence.PersistenceException: No Persistence provider for EntityManager named Service at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61) at de.devboost.quamo.metricprocessor.data.dao.QuamoDAOBase.configure(QuamoDAOBase.java:118) at de.devboost.quamo.metricprocessor.data.dao.QuamoDAOBase.configure(QuamoDAOBase.java:113) at de.devboost.quamo.metricprocessor.data.dao.QuamoDAOBase.getEntityManagerFactory(QuamoDAOBase.java:132) at de.devboost.quamo.metricprocessor.data.dao.QuamoDAOBase.createEntityManager(QuamoDAOBase.java:152) at de.devboost.quamo.metricprocessor.data.dao.QuamoDAOBase.executeInTransaction(QuamoDAOBase.java:359) at de.devboost.quamo.metricprocessor.data.dao.QuamoDAOBase.executeInTransaction(QuamoDAOBase.java:345) at de.devboost.quamo.metricprocessor.data.dao.QuamoDAOBase.executeInTransaction(QuamoDAOBase.java:336) at de.devboost.quamo.metricprocessor.data.dao.QuamoDAOBase.executeInTransaction(QuamoDAOBase.java:328) at de.devboost.quamo.metricprocessor.base.AbstractMetricProcessor.(AbstractMetricProcessor.java:20) at de.devboost.quamo.metricprocessor.metric.NumberOfNatSpecSentences.(NumberOfNatSpecSentences.java:11) at de.devboost.quamo.metricprocessor.rest.MetricProcessorRestController.metricProcessorNatSpecInput(MetricProcessorRestController.java:43) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

iljabauer commented 9 years ago

How do you configure the QuamoDao? you have to name the file persistence.properties and the content should be like: hibernate.connection.driver_class hibernate.connection.url hibernate.connection.username hibernate.connection.password hibernate.hbm2ddl.auto

iljabauer commented 9 years ago

if you instantiate it like QuamoDao(contextClass), it will use: InputStream stream = contextClass.getResourceAsStream("persistence.properties");

to load the properties

pp23 commented 9 years ago

QuamoDAOBase cannot find the persistence.properties(InputStream is null). As context-class I have used the AbstractMetricProcessor-class in the package de.devboost.quamo.metricprocessor.base (just for testing). In this package I have copied the persistence.properties, so I guessed the QuamoDAOBase can find the file, but that's not the case :-(

Also other locations didn't help.

I have pushed the files into (both) git(s).

iljabauer commented 9 years ago

IMHO the contextClass.getResourceAsStream is also looking at resources folder in the same package like the context class, but I'm not sure. I'm pushed a mavenless project of your prototype and added a TestClass, the persistence.properties and the persistence xml where the setup is working.

If you add something to the pom.xml you can copy the dependancies by calling mvn dependency:copy-dependencies

pp23 commented 9 years ago

Okay, after I instantiated QuamoDAO in the rest-class and put the properties-file into the same package it's getting found by the QuamoDAO. But the error keeps the same as before. This is my persistence.properties:

hibernate.connection.driver_class=org.postgresql.Driver hibernate.connection.url=jdbc:postgresql://localhost:5432/quamodb hibernate.connection.username=quamo hibernate.connection.password=quamo hibernate.hbm2ddl.auto=update

btw: postgres prints out the following error:

ERROR: relation "hibernate_sequence" already exists STATEMENT: create sequence "hibernate_sequence"

iljabauer commented 9 years ago

Did you also placed the persistence.xml in resources/META-INF?

pp23 commented 9 years ago

Oh okay, I thought because I didn't need any persistence.xml wit jpa-data I also don't need it with HEDL. I will try it with a persistence.xml

iljabauer commented 9 years ago

Yeah, ist a very simple one. You can look in my branch ;-)

pp23 commented 9 years ago

studium@WOPR ~/workspace/KP14 $ git checkout ibauer Gewechselt zu Branch 'ibauer' Ihr Branch ist auf dem selben Stand wie 'origin/ibauer'. studium@WOPR ~/workspace/KP14 $ git pull Already up-to-date. studium@WOPR ~/workspace/KP14 $ find . | grep persistence.xml studium@WOPR ~/workspace/KP14 $

Could it be, that the persistence.xml won't be commited by eclipse?

iljabauer commented 9 years ago

ok, something went wrong during pushing. I pushed it again. But here is the file:

<?xml version="1.0" encoding="UTF-8"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">

        <persistence-unit name="Service" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
        </persistence-unit>

    </persistence>

And it lives in ./de.devboost.quamo.metricprocessor.prototype.mavenless/resources/META-INF/persistence.xml

pp23 commented 9 years ago

Okay, nice. Maven and HEDL can work together :-) Finished after all in all 2h