[groovy-user] Problems Persisting Java Objects and Grails Domain Objects Together

瀏覽次數:0 次
跳到第一則未讀訊息

dgalewsky

未讀,
2009年10月2日 下午1:02:532009/10/2
收件者:us...@groovy.codehaus.org

We are having problems trying to integrate and persist Java objects
intermingled with Gorm/Groovy domain objects and need some help.

We are trying to create some objects in Java, annotate them with Hibernate
annotations and then persist them - along with Grails/GORM domain objects.

Here is an example Java object - annotated to work with Hibernate (this
object works fine as a standalone Java/Hibernate object - and even works
fine standalone in the Grails world):

package org.tdl.txlor.publisher;
import javax.persistence.*;

@Entity
@Table(name="publisher")
public class Publisher {

@Id
@Column(name="USER_ID")
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;

@Column(name="MYSTATE",nullable=true,unique=false)
private String myState;

public Publisher() {
System.out.println("* * * * * Publisher Constructor * * * * *");
}

public Publisher(String state) {
System.out.println("Publisher Constructor val: " + state);
myState = state;
}

public String publish(String path){
System.out.println("in publisher");
return "published - " + path;
}
}
--------------

Here is a sample User Grails object (that needs to have a publisher object -
persisted along with it). If I comment out the Publisher variable -
everything is fine.:

import org.tdl.txlor.publisher.*;

class User {
String firstname
String lastname
Publisher pub

static constraints = {
firstname blank:false, nullable:false
lastname blank:false, nullable:false
}
}

---------

Here is the hibernate.cfg.xml file that should tie all of this together:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<mapping package="org.tdl.txlor.publisher" />
<mapping class="org.tdl.txlor.publisher.Publisher" />

</session-factory>
</hibernate-configuration>

--------

If I try to run Grails with this set of relationships - it blows up - in the
process of setting up the runtime environment (before the 'server running'
message)

ERROR mortbay.log - Nested in
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'messageSource': Initialization of bean failed; nested exception
is org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'transactionManager': Cannot resolve reference to bean
'sessionFactory' while setting bean property 'sessionFactory'; nested
exception is org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'sessionFactory': Invocation of init method failed;
nested exception is java.lang.NullPointerException:
java.lang.NullPointerException
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivileged(Native Method)
at grails.web.container.EmbeddableServer$start.call(Unknown Source)
at
_GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy:145)
at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy)
at
_GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:274)
at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:137)
at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
at _GrailsRun_groovy.runInline(_GrailsRun_groovy:104)
at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:58)
at RunApp$_run_closure1.doCall(RunApp:33)
at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:344)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:334)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.processTargets(Gant.groovy:495)
at gant.Gant.processTargets(Gant.groovy:480)

I have had no problems writing/running plain old Groovy/Grails code. I have
been able to easily create and call methods on arbitrary Java objects. I am
just having a problem persisting domain objects that have Java objects as
members.

Can anyone help me figure this out - or tell me if it is even possible?

Thanks
Dan Galewsky
Texas Digital Library


--
View this message in context: http://www.nabble.com/Problems-Persisting-Java-Objects-and-Grails-Domain-Objects-Together-tp25716749p25716749.html
Sent from the groovy - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Graeme Rocher

未讀,
2009年10月2日 下午2:14:472009/10/2
收件者:us...@groovy.codehaus.org
You probably want the Grails list, this is the Groovy list

--
Graeme Rocher
Head of Grails Development
SpringSource - Weapons for the War on Java Complexity
http://www.springsource.com

回覆所有人
回覆作者
轉寄
0 則新訊息