Sometimes Java pisses me off

Discussion in 'OT Technology' started by Peyomp, Jul 17, 2007.

  1. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    I just had to create an entire class to get the ORM library to let me return a query that has one row, and 2 values. I can't just get at the values. I have to create an object for them to map to. Holy beat around the fucking bush. The fucking tools start to work against you sometimes. Makes me miss perl, and long for ruby or python.
     
  2. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    Nothings wrong with that. A Database Access Object gives a higher level of abstraction, removing the SQL from code.
     
  3. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    ORM is great. That being said, sometimes you just need a couple values from a database. Now, you don't want to go with raw JDBC and manage that shit. A good ORM library provides the ability to pass some raw SQL and get a resultset. This one doesn't. Actually, I have the query in XML and I can't get a result from it unless I define a JavaBean to map the results to. There IS something wrong with that. I can isolate the SQL in XML, or in a Database oriented class, thats fine. But don't make me create a fake Javabean that shouldn't exist just to grab two values. When I have to do that, it is not saving me time or adding clarity. The tool is adding complexity.

    Thus, Java sometimes pisses me off. Its inflexible. The constraints are there for a reason, but sometimes they feel like handcuffs. They don't let me use my best judgement to sometimes take shortcuts.
     
  4. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    Perhaps I'm misunderstanding something but why do you need a JavaBean to handle this?? JBs are only a specific type of class structure.

    We were able to establish a connection, pass a query to the DB and get the result set from anywhere. Sometimes it was in a servlet, sometimes in an scriptlet or expression and sometimes we did it in a bean.

    The one thing is, you must keep your connection open to get at the result set values, unlike PHP. Perhaps that's your issue.

    Anyways if you wanna post specifics I'll try to help or you can PM me. Not sure if I'll be any help but I'll certainly give it a shot.
     
  5. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    I could manage my own JDBC connection and grab the value manually, but we don't do that anywhere else in the code. We use an ORM library so that we never mess with ODBC directly. It would be silly to manually create a new connection for this one query. So I jump through a hoop, create a little JavaBean for the response. Get it? Its not a problem in that I'm stuck. Its a problem in that my overly OO library has offended me.
     
  6. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    Java is hard to love sometimes

    How's the app coming?
     
  7. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    I guess I get it but I'm not familiar with the ORM library.

    Perhaps a blended approach would help if you have a couple of these types of issues. Maybe set up connection pooling to handle the connections and you can get a quick one if you need it....but if it's only a one time thing, prolly not a good idea.
     
  8. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    A blended approach is best... the library should have it. This kind of thing happens all the time. Its just Java.
     
  9. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    This sort of thing meaning dealing with DBs or does this also come up with other types of programming issues in Java??
     
  10. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    It comes up with everything in Java.
     
  11. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Yeah, Java is nice in many ways, especially now with generics. But there are certainly times when it bugs the hell out of me.
     
  12. Nocera

    Nocera ...

    Joined:
    Aug 9, 2000
    Messages:
    1,307
    Likes Received:
    0
    Location:
    Long Island, NY
    3 places that should never be accessing the DB. :nono:

    Peyomp: Which ORM library are you using?
     
  13. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    I can't say.
     
  14. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    Huh?? Why is that?
     
  15. Nocera

    Nocera ...

    Joined:
    Aug 9, 2000
    Messages:
    1,307
    Likes Received:
    0
    Location:
    Long Island, NY
    Well, a bean might be ok. But servlets and scriptlets (or anything on a JSP) should not access the DB. It wouldn't follow a proper MVC design. DB access should occur in the model layer (or a data access layer underneath it). Servlets are in the Controller layer and scriptlets are in your View layer. Both shouldn't be concerned with data access.

    http://java.sun.com/blueprints/patterns/MVC-detailed.html
     
  16. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    Ahh....our prof mentioned the MVC framework but that's all he did, mention it. We never studied it seemed like he sort of dismissed it.

    Thanks for the heads up....I should really spend some time on that.
     

Share This Page