Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: 2.0-M2
-
Fix Version/s: None
-
Component/s: None
-
Labels:
-
Testcase included:yes
Description
Background
This project is using a JPA domain model as described here:
http://blog.springsource.com/2010/08/26/reuse-your-hibernatejpa-domain-model-with-grails/
The JPA domain classes and the service layer are in separate JAR files that are configured as dependencies in BuildConfig.groovy. The Spring config is loaded from an XML file within the service layer JAR by adding the following to resources.groovy
importBeans('classpath:/applicationContext-services.xml')
In Grails 2.0.0M1, JPA domain classes were not being recognised as Grails domain classes. I have verified that this problem has been resolved. However, it now seems that it is not possible to persist domain classes using the JPA EntityManager.
Run Test Case
To run the attached application, unzip dependencies.zip and run the following from the root
mvn clean install -DrefreshDB -DskipTests
This will install the domain and service layers dependencies in your Maven repository and create an 'esd' MySQL database on localhost. Creating the database assumes that the local MySQL server runs on the default port and has a blank root password. If this isn't convenient, remove -DrefreshDB from the command above and manually create a database on localhost using the following DDL
create database esd;
use esd;
create table user (
id bigint not null auto_increment,
email varchar(255),
password varchar(255),
primary key (id)
);
Then unzip and run the Grails app in jpabug2.zip
Reproduce Bug
Once the app starts, if you click on the SignUpController links, the following code is executed:
class SignUpController {
UserManager userManager
def signUp = {
User user = new User(email: 'foo@bar.com', password: 'password')
if (params.gorm) {
user.save(failOnError: true)
render(text: "Number of users: ${User.count()}")
} else {
userManager.saveOrUpdate(user)
render(text: "Number of users: ${User.count()}")
}
}
}
userManager.saveOrUpdate(user) tries to save a User using the JPA EntityManager
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW) public E saveOrUpdate(E entity) { return entityManager.merge(entity); }
You can attempt to save a user using the GORM save() method (instead of the JPA EntityManager) by appending "?gorm=true" to the URL above. As you can see from the output, the GORM save method is successful, but the JPA EntityManager manager fails.
Perhaps I'm mistakenly assuming that it should be possible to use the EntityManager when using a JPA domain model?
-
Hide
- dependencies.zip
- 10/Sep/11 5:47 PM
- 29 kB
- Donal Murtagh
-
- esd-root/.project 0.4 kB
- esd-root/.../org.maven.ide.eclipse.prefs 0.2 kB
- esd-root/domain/.classpath 0.8 kB
- esd-root/domain/.project 1 kB
- esd-root/.../org.eclipse.jdt.core.prefs 0.5 kB
- esd-root/.../org.eclipse.wst.common.component 0.3 kB
- esd-root/.../org.eclipse.wst.common.project.facet.core.xml 0.2 kB
- esd-root/.../org.maven.ide.eclipse.prefs 0.2 kB
- esd-root/domain/domain.iml 3 kB
- esd-root/domain/pom.xml 6 kB
- esd-root/domain/.../model/BaseObject.java 0.4 kB
- esd-root/domain/src/.../com/model/User.java 2 kB
- esd-root/domain/src/.../META-INF/MANIFEST.MF 0.0 kB
- esd-root/domain/.../database.properties 0.1 kB
- esd-root/domain/.../META-INF/persistence.xml 0.4 kB
- esd-root/domain/src/.../resources/rebel.xml 0.4 kB
- esd-root/esd-managers-test.log 0.0 kB
- esd-root/esd-root.iml 1 kB
- esd-root/managers/.classpath 0.9 kB
- esd-root/managers/.project 1 kB
- esd-root/.../org.eclipse.jdt.core.prefs 0.5 kB
- esd-root/.../org.eclipse.wst.common.component 0.3 kB
- esd-root/.../org.eclipse.wst.common.project.facet.core.xml 0.2 kB
- esd-root/.../org.maven.ide.eclipse.prefs 0.2 kB
- esd-root/managers/managers.iml 6 kB
- esd-root/managers/pom.xml 4 kB
- esd-root/managers/Readme.txt 3 kB
- esd-root/managers/.../BaseManager.java 1.0 kB
- esd-root/managers/.../AbstractManager.java 2 kB
- esd-root/managers/.../BaseManagerImpl.java 2 kB
-
Hide
- jpabug2.zip
- 10/Sep/11 5:47 PM
- 116 kB
- Donal Murtagh
-
- jpabug2/.classpath 0.7 kB
- jpabug2/.project 0.5 kB
- jpabug2/.../org.codehaus.groovy.eclipse.preferences.prefs 0.1 kB
- jpabug2/application.properties 0.1 kB
- jpabug2/grails-app/conf/BootStrap.groovy 0.1 kB
- jpabug2/grails-app/.../BuildConfig.groovy 2 kB
- jpabug2/grails-app/conf/Config.groovy 4 kB
- jpabug2/grails-app/.../DataSource.groovy 0.2 kB
- jpabug2/grails-app/.../hibernate.cfg.xml 0.4 kB
- jpabug2/grails-app/.../resources.groovy 0.6 kB
- jpabug2/grails-app/.../UrlMappings.groovy 0.2 kB
- jpabug2/.../SignUpController.groovy 0.5 kB
- jpabug2/grails-app/.../messages.properties 3 kB
- jpabug2/.../messages_cs_CZ.properties 3 kB
- jpabug2/.../messages_da.properties 3 kB
- jpabug2/.../messages_de.properties 4 kB
- jpabug2/.../messages_es.properties 3 kB
- jpabug2/.../messages_fr.properties 2 kB
- jpabug2/.../messages_it.properties 2 kB
- jpabug2/.../messages_ja.properties 4 kB
- jpabug2/.../messages_nl.properties 3 kB
- jpabug2/.../messages_pt_BR.properties 3 kB
- jpabug2/.../messages_pt_PT.properties 3 kB
- jpabug2/.../messages_ru.properties 4 kB
- jpabug2/.../messages_sv.properties 3 kB
- jpabug2/.../messages_th.properties 5 kB
- jpabug2/.../messages_zh_CN.properties 2 kB
- jpabug2/grails-app/views/error.gsp 0.3 kB
- jpabug2/grails-app/views/index.gsp 3 kB
- jpabug2/grails-app/.../layouts/main.gsp 2 kB
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
After reading a bit more about the subject, it seems that if you want to use the EntityManager you must install the GORM-JPA plugin. However, judging by the example persistence.xml shown on that plugin's page, it looks like it only supports JPA 1.0, is that right?
Just in case the explanation above is unclear, once the application has started, use the URL:
http://localhost:8080/jpabug2/signUp/signUp to try and save a user with the EntityManager (this should fail)
Use the URL http://localhost:8080/jpabug2/signUp/signUp?gorm=true to try and save a user with GORM (which should succeed)