-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Form to persist a @OneToMany relation
PostPosted: Sun Apr 25, 2010 10:54 am 
Beginner
Beginner

Joined: Sat Oct 03, 2009 1:51 pm
Posts: 26
Hello!
I have a form to persist a relationship one-to-many, I have a Contact class another Message class. A contact can have multiple messages and a message is just a touch.
The tables are already created, my question is how is the form in JSP:
Code:
<form action="contato/adiciona" method="post">
   
<ul>
   <c:forEach var="error" items="${errors}">   
     <li>${error.message}</li>   
   </c:forEach> 
</ul>
<ul>   
   <li><label for="nome">Nome</label>
   <div><input name="contato.nome" class="element text small" type="text" maxlength="255" value="" />
   </div>
   </li>
   
   <li><label for="email">E-mail</label>   
   <div><input name="contato.email" class="element text large" type="text" maxlength="255" value="" />
   </div>
   </li>
   
   <li><label for="assunto">Assunto</label>   
   <div><input name="contato.mensagem.assunto" class="element text large" type="text" maxlength="255" />
   </div>
   </li>   
   
   <li><label for="mensagem">Mensagem</label>   
   <div><textarea name="contato.mensagem.mensagem" class="element textarea large" rows="5" cols="80"></textarea>
   </div>
   </li>

</ul>
<input type="submit" name="submit" value="Enviar" />
</form>

This is my doubt is in relation to the subject (assunto) and message (mensagem) fields.
This is my class Message and Contact:
Contact Class:
Code:
@Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Long idContato;
   private String nome;
   private String email;
   @OneToMany(targetEntity=Mensagem.class ,cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "contato",orphanRemoval=true)
   private List<Mensagem> mensagens;
   
   public Contato() {
   }
   
   public Contato(Long idContato, String nome, String email,
       List<Mensagem> mensagens) {
      this.idContato = idContato;
      this.nome = nome;
      this.email = email;
      this.mensagens = mensagens;
   }


   public List<Mensagem> getMensagens() {
      return mensagens;
   }

   public void setMensagens(List<Mensagem> mensagens) {
      this.mensagens = mensagens;
   }

   public Long getIdContato() {
      return idContato;
   }
   public void setIdContato(Long idContato) {
      this.idContato = idContato;
   }
   public String getNome() {
      return nome;
   }
   public void setNome(String nome) {
      this.nome = nome;
   }
   public String getEmail() {
      return email;
   }
   public void setEmail(String email) {
      this.email = email;
   }
}

Message class:
Code:
@Entity
public class Mensagem {
   
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Long idMensagem;
   private String assunto;
   private String mensagem;
   @ManyToOne
   private Contato contato;
   
   public String getAssunto() {
      return assunto;
   }
   public void setAssunto(String assunto) {
      this.assunto = assunto;
   }   
   
   public Mensagem() {
   }
   
   public Mensagem(Long idMensagem, String assunto, String mensagem,
         Contato contato) {
      this.idMensagem = idMensagem;
      this.assunto = assunto;
      this.mensagem = mensagem;
      this.contato = contato;
   }
   public Long getIdMensagem() {
      return idMensagem;
   }
   public void setIdMensagem(Long idMensagem) {
      this.idMensagem = idMensagem;
   }
   public String getMensagem() {
      return mensagem;
   }
   public void setMensagem(String mensagem) {
      this.mensagem = mensagem;
   }
   public Contato getContato() {
      return contato;
   }
   public void setContato(Contato contato) {
      this.contato = contato;
   }

}

The StackTrace is:
Code:
11:51:03,898 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for ContatoController.adiciona(Contato) as [contato]
11:51:03,901 DEBUG [AsmBasedTypeCreator ] Parameter names found for creating type are: [Contato]
11:51:03,902 DEBUG [AsmBasedTypeCreator ] Method for field 'Contato' being defined for type Lbr/com/imobiliaria/bean/Contato;
11:51:03,906 DEBUG [AsmBasedTypeCreator ] Methods: [public br.com.imobiliaria.bean.Contato ContatoController$adiciona$472914723$4.getContato(), public void ContatoController$adiciona$472914723$4.setContato(br.com.imobiliaria.bean.Contato)]
11:51:03,906 DEBUG [AsmBasedTypeCreator ] Fields: [private br.com.imobiliaria.bean.Contato ContatoController$adiciona$472914723$4.Contato_]
11:51:03,906 DEBUG [CacheBasedTypeCreator] cached generic type for method [DefaultResourceMethod: ContatoController.adicionaContatoController.adiciona(Contato)]
11:51:03,907 DEBUG [OgnlParametersProvider] Applying contato.nome with [asda]
11:51:03,985 DEBUG [OgnlParametersProvider] Applying contato.mensagem.mensagem with [da]
11:51:03,991 DEBUG [OgnlParametersProvider] cant find property for expression contato.mensagem.mensagem ignoring
11:51:03,992 DEBUG [OgnlParametersProvider] Applying contato.email with [sd]
11:51:03,992 DEBUG [OgnlParametersProvider] Applying contato.mensagem.assunto with [adsa]
11:51:03,994 DEBUG [OgnlParametersProvider] cant find property for expression contato.mensagem.assunto ignoring
11:51:03,994 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for ContatoController.adiciona(Contato) as [contato]
11:51:03,997 DEBUG [ParametersInstantiatorInterceptor] Parameter values for [DefaultResourceMethod: ContatoController.adicionaContatoController.adiciona(Contato)] are [br.com.imobiliaria.bean.Contato@1f85a86]
11:51:04,040 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ExecuteMethodInterceptor
11:51:04,040 DEBUG [ExecuteMethodInterceptor] Invoking ContatoController.adiciona(Contato)
Hibernate:
    insert
    into
        Contato
        (email, nome)
    values
        (?, ?)
11:51:04,627 DEBUG [DefaultLogicResult  ] redirecting to class ContatoController
11:51:04,630 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for ContatoController.mensagem() as []
11:51:04,630 DEBUG [AsmBasedTypeCreator ] Trying to make class for ContatoController$mensagem$2026807902$5
11:51:04,631 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for ContatoController.mensagem() as []
11:51:04,631 DEBUG [AsmBasedTypeCreator ] Parameter names found for creating type are: []
11:51:04,631 DEBUG [AsmBasedTypeCreator ] Methods: []
11:51:04,631 DEBUG [AsmBasedTypeCreator ] Fields: []

As it stands does not write the subject (assunto) and message (mensagem), this is the problem. My classes are correct?
I appreciate the help.
Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.