Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 692C463ED for ; Sat, 23 Jul 2011 15:55:23 +0000 (UTC) Received: (qmail 15718 invoked by uid 500); 23 Jul 2011 15:55:23 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 15624 invoked by uid 500); 23 Jul 2011 15:55:22 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 15614 invoked by uid 99); 23 Jul 2011 15:55:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Jul 2011 15:55:21 +0000 X-ASF-Spam-Status: No, hits=1.6 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of curtisr7@gmail.com designates 209.85.215.46 as permitted sender) Received: from [209.85.215.46] (HELO mail-ew0-f46.google.com) (209.85.215.46) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Jul 2011 15:55:14 +0000 Received: by ewy4 with SMTP id 4so3107126ewy.33 for ; Sat, 23 Jul 2011 08:54:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=/SDcsZfyglzjo6hwanT4t6Vew0sbOKwcwoCtDp6CR5E=; b=X7cdB/rpnciaxlqlgwfnLQEBBGXyNbXXrjuSGV1KNm4Bl4RdVYrRD1HyoBrMtOjnDY x2GsX5PIpC92R24AqVLo13Z/CW39jlhL0HfWvH+tAifDwdGT6NtfFhZE12HWyfg3YeZK sUzTBc5vxqDuWFh8KyDBb/gSSZoxPt8swrLVI= MIME-Version: 1.0 Received: by 10.213.16.144 with SMTP id o16mr1114020eba.102.1311436494000; Sat, 23 Jul 2011 08:54:54 -0700 (PDT) Received: by 10.213.34.132 with HTTP; Sat, 23 Jul 2011 08:54:53 -0700 (PDT) In-Reply-To: References: Date: Sat, 23 Jul 2011 10:54:53 -0500 Message-ID: Subject: Re: openjpa 2 ManyToOne in tomcat From: Rick Curtis To: users@openjpa.apache.org Content-Type: multipart/alternative; boundary=0015174bf1c05ed3e304a8be9acc X-Virus-Checked: Checked by ClamAV on apache.org --0015174bf1c05ed3e304a8be9acc Content-Type: text/plain; charset=ISO-8859-1 Romain - > I get a NPE using the relation between both entities (Post of a blog and its comments). Are you able to find your Post / Comments if you are to execute an EntityManager.find(...) operation? > It seems to work in standalone but not Tomcat so i guess there is something specific, can you help me to look where i should? Does it need some Jndi things? This leads me to believe that there is some sort of connection configuration issue. How are you configuring your DB in JSE vs Tomcat? Thanks, Rick On Wed, Jul 20, 2011 at 11:59 PM, Romain Manni-Bucau wrote: > Hi, i'm in tomcat and i have a ManyToOne relation. > > I get a NPE using the relation between both entities (Post of a blog and > its > comments). > > It seems to work in standalone but not Tomcat so i guess there is something > specific, can you help me to look where i should? Does it need some Jndi > things? > > I enhanced entities with the maven plugin like it: > > > org.apache.openjpa > openjpa-maven-plugin > 2.2.0-SNAPSHOT > > org/superbiz/model/*.class > true > true > > > > enhancer > process-classes > > enhance > > > > > > org.apache.openjpa > openjpa > 2.0.1 > > > > > > > > Here are entities: > > ============ Post.java > > package org.superbiz.rest.model; > > import javax.annotation.PostConstruct; > import javax.persistence.CascadeType; > import javax.persistence.Entity; > import javax.persistence.GeneratedValue; > import javax.persistence.Id; > import javax.persistence.Lob; > import javax.persistence.ManyToOne; > import javax.persistence.NamedQueries; > import javax.persistence.NamedQuery; > import javax.persistence.OneToMany; > import javax.validation.Valid; > import javax.validation.constraints.NotNull; > import javax.validation.constraints.Past; > import javax.validation.constraints.Size; > import javax.xml.bind.annotation.XmlRootElement; > import java.util.ArrayList; > import java.util.Date; > import java.util.List; > > @Entity > @NamedQueries({ > @NamedQuery(name = "post.list", query = "select p from Post p") > }) > @XmlRootElement(name = "post") > public class Post { > @Id @GeneratedValue private long id; > @Past private Date created; > @NotNull @Size(min = 1) private String title; > @NotNull @Size(min = 1) @Lob private String content; > @ManyToOne @Valid private User user; > @OneToMany(mappedBy = "post", cascade = CascadeType.ALL) private > List comments; > > @PostConstruct public void create() { > created = new Date(); > } > > public Post title(final String title) { > this.title = title; > return this; > } > > public Post content(final String content) { > this.content = content; > return this; > } > > public Post user(final User user) { > this.user = user; > return this; > } > > public long getId() { > return id; > } > > public void setId(long id) { > this.id = id; > } > > public String getTitle() { > return title; > } > > public void setTitle(String title) { > this.title = title; > } > > public String getContent() { > return content; > } > > public void setContent(String content) { > this.content = content; > } > > public User getUser() { > return user; > } > > public void setUser(User user) { > this.user = user; > } > > public List getComments() { > if (comments == null) { > comments = new ArrayList (); > } > return comments; > } > > public void setComments(List comments) { > this.comments = comments; > } > > public void addComment(final Comment comment) { > getComments().add(comment); > } > > public Date getCreated() { > return created; > } > > public void setCreated(Date created) { > this.created = created; > } > } > > ============ Comment.java > > package org.superbiz.rest.model; > > import javax.annotation.PostConstruct; > import javax.persistence.Entity; > import javax.persistence.GeneratedValue; > import javax.persistence.Id; > import javax.persistence.Lob; > import javax.persistence.ManyToOne; > import javax.persistence.NamedQueries; > import javax.persistence.NamedQuery; > import javax.validation.Valid; > import javax.validation.constraints.NotNull; > import javax.validation.constraints.Past; > import javax.validation.constraints.Size; > import javax.xml.bind.annotation.XmlRootElement; > import java.util.Date; > > @Entity > @NamedQueries({ > @NamedQuery(name = "comment.list", query = "select c from Comment c") > }) > @XmlRootElement(name = "comment") > public class Comment { > @Id @GeneratedValue private long id; > @Past private Date created; > @NotNull @Size(min = 1) private String author; > @NotNull @Size(min = 1) @Lob private String content; > @ManyToOne(optional = false) @Valid private Post post; > > @PostConstruct public void create() { > created = new Date(); > } > > public Comment author(final String author) { > this.author = author; > return this; > } > > public Comment content(final String content) { > this.content = content; > return this; > } > > public long getId() { > return id; > } > > public void setId(long id) { > this.id = id; > } > > public String getAuthor() { > return author; > } > > public void setAuthor(String author) { > this.author = author; > } > > public String getContent() { > return content; > } > > public void setContent(String content) { > this.content = content; > } > > public Post getPost() { > return post; > } > > public void setPost(Post post) { > this.post = post; > } > > public Date getCreated() { > return created; > } > > public void setCreated(Date created) { > this.created = created; > } > } > > > - Romain > -- *Rick Curtis* --0015174bf1c05ed3e304a8be9acc--