-->
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.  [ 2 posts ] 
Author Message
 Post subject: direct insert in one-to-many
PostPosted: Wed Aug 25, 2004 3:47 pm 
Beginner
Beginner

Joined: Fri Apr 16, 2004 10:25 am
Posts: 44
Location: Brazil
I have a one-to-many association and my class is mapped like this

Code:
public class ControleLote {
   private Arquivo codArquivo;
   private Integer codLote;
   private String dscObs;
   private String indSituacao;
   private Integer quantRegArquivo;
   private Date datIni;
   private Date datFim;
   
   private Set registros;
   
   public Arquivo getCodArquivo() {
      return codArquivo;
   }
   public void setCodArquivo(Arquivo codArquivo) {
      this.codArquivo = codArquivo;
   } ....


In my code I have to associate a new ControleLote with a existent Arquivo which I have the ID

Is there a way I can set the codArquivo without perform a query in the DB to retrieve the hole Arquivo, just using the ID.

or better, can I do :

Code:
         
         Arquivo arquivo = new Arquivo();
         arquivo.setCodArquivo(new Integer(codArq));
         
         ControleLoteDao controleLoteDao = hibernateDaoFactory.getControleLoteDao();
         ControleLote controleLote = new ControleLote();
         controleLote.setCodArquivo(arquivo);
         controleLote.setDatIni(new Date());
         controleLoteDao.create(controleLote);
         intLote = controleLote.getCodLote();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 12:51 pm 
Beginner
Beginner

Joined: Fri Apr 16, 2004 10:25 am
Posts: 44
Location: Brazil
Another question related to this one.

sometimes I use direct connection using jdbc to retrieve a object for performance sake.

In the code above I have to set the association codOrg which is another POJO
I have the ID of Org, what should I do? create a bean, set the ID and associate with my cliente bean?

Code:
      String query  ="select COD_ORG, DAT_INCLUSAO, DSC_EMAIL, IND_SITUA_FORNEC, NOM_CLI, VLR_SLD_DEV, COD_CLI from SSC_cliente where cod_cli_ext=?";
      try {
         Connection conn = session.connection();
         PreparedStatement ps = conn.prepareStatement(query);
         ps.setString(1,codClienteExt);
         ResultSet rs = ps.executeQuery();
         if (rs.next()) {
            cli = new Cliente();
            cli.setCodOrg(?????);
         }
      } catch (Exception e) {
         e.printStackTrace();
         throw new DaoException();
      }


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

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.