-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate advantages question
PostPosted: Tue Aug 16, 2005 3:55 am 
Newbie

Joined: Wed Aug 03, 2005 3:38 am
Posts: 3
Hi All

I'm totally new to Hibernate.

I´ve an application that will store and retrieve some simple data from a DB (MySQL, by now...) and I wonder if Hbiernate could be needed/useful for me.

The code where my application will store/retrieve data is a Bean then persistence is kept and Hibernate will not help me at this point.

After read docs I think the only way that Hibernate could help me is the use of his own SQL language to allow me to change DB easily in the future but as far as I know my querys are so simple, I'm not sure if it's really needed to learn Hibernate and to place a lot of extra code for this.

Am I right or wrong ? Could Hibernate make more than I expresed above ?

My code is something like this:

------------------
Code:
public class RDBMTicketRegistry implements TicketRegistry {
   private Connection con = getConnection();
   
   /** The Commons Logging instance. */
    private final Log log = LogFactory.getLog(getClass());

   
   /**
    * Add a ticket to the DB
    */
   public void addTicket(final Ticket ticket) {
      
      if (log.isDebugEnabled())
         log.debug("Entre en addTicket");
      
      if (ticket == null) {
            throw new IllegalArgumentException("ticket cannot be null");
        }

      try {                  
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream oos = new ObjectOutputStream(baos);
         oos.writeObject(ticket);
         // serialize the employee object into a byte array
         byte[] ticketAsBytes = baos.toByteArray();
         PreparedStatement pstmt = con.prepareStatement
                  ("INSERT INTO tickets VALUES(?, ?)");
         ByteArrayInputStream bais =
            new ByteArrayInputStream(ticketAsBytes);
         // bind our byte array  to the emp column
         pstmt.setString(1, ticket.getId());
         pstmt.setBinaryStream(2,bais, ticketAsBytes.length);
         pstmt.executeUpdate();         
         pstmt.close();                           
      } catch(IOException ioe) {
         log.error("Error IOE al insertar ticket id " + ticket.getId() + " exception: " + ioe.getMessage());
      } catch(SQLException sqle) {
         log.error("Error SQL al insertar ticket id " + ticket.getId() + " exception: " + sqle.getMessage());
      }
   }
   
   
   
   
   /**
    *
    * @return
    */
   private Connection getConnection() {
      Connection c = null;
      
      System.out.println("Entre en getConnection");

      
      try {
         // Obtain our environment naming context
         Context initCtx = new InitialContext();
         Context envCtx = (Context) initCtx.lookup("java:comp/env");

         // Look up our data source
         DataSource ds = (DataSource) envCtx.lookup("jdbc/MySQLDB");

         // Allocate and use a connection from the pool
         c = ds.getConnection();
      } catch(Exception e) {
         log.error("Excepcion al conectar a Db " + e.getMessage());
      }      
      
      if (c != null) {         
         System.out.println("Connection a DB es Ok");
      }
      
      return c;
   }
}




And there are mnethods to getTickets and deleteTickets in the same way.



Thanks in advance

J

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 3:25 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
From your code, you are storing the entire object as a blob, leaving just id for referencing...

We had a project where we did this a while back for performance...but soon ran into problems. None of the fields were indexable, or searchable. Every time the customers asked for another searchable field, we added another field in the ticket table, while also storing the whole object in the database.
Eventually, started getting more and more problems with values in table not matching values in blob. Wouldn't advise using this approach.

Hibernate is for relational to object mapping. you don't really have a relational model of the data if everything is in a blob.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 6:36 am 
Newbie

Joined: Wed Aug 03, 2005 3:38 am
Posts: 3
anar wrote:
From your code, you are storing the entire object as a blob, leaving just id for referencing...

We had a project where we did this a while back for performance...but soon ran into problems. None of the fields were indexable, or searchable. Every time the customers asked for another searchable field, we added another field in the ticket table, while also storing the whole object in the database.
Eventually, started getting more and more problems with values in table not matching values in blob. Wouldn't advise using this approach.

Hibernate is for relational to object mapping. you don't really have a relational model of the data if everything is in a blob.



Hello

Thanks for your reply.

You are wrong in this point.

If you check my code, I'm storing ticket_id as string and the whole serializable ticket object as blob.

As far as Ticket_id is a primary key, each ticket could be easily found and indexed.

This ticket table is from my Yale´s CAS server implementation and works without problems. By default, CAS store tickets in a HashMap but as I´ll use clustered servers I´ll need to store tickets in a isolated RDBM .

My original question was orientated to know if Hibernate could provide me with some useful methods that make this simple proces more robust and independent from a DB brand.

Thanks

J


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 12:06 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 3:15 pm
Posts: 29
xleyba, your right. If all you are doing are simple inserts and selects then from a complexity perspective and having to spend time learning to use hibernate perspective it is propbably not for you. If you start building this application and it has the potential to grow or you get requirements that increase queries/schema then you would probably want an ORM solution.
Hope this helps.
B

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 12:08 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 3:15 pm
Posts: 29
xleyba, your right. If all you are doing are simple inserts and selects then from a complexity perspective and having to spend time learning to use hibernate perspective it is propbably not for you. If you start building this application and it has the potential to grow or you get requirements that increase queries/schema then you would probably want an ORM solution.
Hope this helps.
B

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 5:42 am 
Newbie

Joined: Wed Aug 03, 2005 3:38 am
Posts: 3
bigbbri wrote:
xleyba, your right. If all you are doing are simple inserts and selects then from a complexity perspective and having to spend time learning to use hibernate perspective it is propbably not for you. If you start building this application and it has the potential to grow or you get requirements that increase queries/schema then you would probably want an ORM solution.
Hope this helps.
B



Thanks for your reply.

J


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.