facebook

[Closed] Hibernate POJO wiz question – why pojo*Id.java?

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #250742 Reply

    Hi all,
    I’ve started using MyEclipse to do Hibernate mappings, but I noticed that besides generating the abstract pojo, the pojo and the *.hbm.xml, a pojoId.java class witht the properties is generated as well. It turns out that I need to do some indirection to get to the pojo, and I can’t use full featured HQL directy on the pojo either

    e.g.

    query = session.createQuery(“from LookUpBillType lbt”);
    Iterator it = query.iterate();
    while(it.hasNext()){
    LookUpBillTypeId id = ((LookUpBillType) it.next()).getId();
    String desc = id.getDescription();
    }

    instead of just saying

    query = session.createQuery(“select lbt.description from LookUpBillType lbt);
    List result = query.list();

    for(Object output : result){
    String desc = (String) output;
    }

    Will this feature be continued? It seems to be an inconvenience unless I’ve got it fugured out all wrong. If I do, please tell me what I should do instead.

    Thanks,
    Jim

    #250775 Reply

    Riyad Kalla
    Member

    Jim,
    That sounds strange, can you provide the create-table statement for your table you are mapping? It should just be mapping a single POJO for you, unless your PK is really strange…

    #250780 Reply

    Hi Riyad,
    I just generated it, and it doesn’t seem to be anything out of the ordinary.

    I can’t perform any restrictions either (Where, Order By, etc.) with the HQL.

    Here’s the create-table script from SQL 2000:

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[LookUpBillType]’) and OBJECTPROPERTY(id, N’IsUserTable’) = 1)
    drop table [dbo].[LookUpBillType]
    GO

    CREATE TABLE [dbo].[LookUpBillType] (
    [BillType] [smallint] NULL ,
    [BillCode] [smallint] NULL ,
    [Tier] [smallint] NULL ,
    [Description] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
    ) ON [PRIMARY]
    GO

    Of note — my manager had the same thing happen to him with another POJO he generated with the 4.1.1 hibernate mapper

    Thanks,
    Jim

    #250781 Reply

    Could this have anything to do with the type of ID Generator that I’ve selected? That’s the only thing I can think of at the moment.

    Thanks,
    Jim

    #250788 Reply

    I figured it out – since the table didn’t have a primary key, Hibernate created one of its own and put all of the properties in the pojoId.java class

    Other folks can check this out too:
    file:///C:/devlibs/hibernate-3.1/doc/reference/en/html/mapping.html#mapping-declaration-compositeid

    Solution: *add a primary key to your database like you’re supposed to*

    FYI: I inherited the database — I know better than to not set a primary key 😉

    Hope this helps other folks. 🙂

    Thanks,
    Jim

    #250799 Reply

    Riyad Kalla
    Member

    Ahh, great catch Jim, thanks for following up.

    #250818 Reply

    Oops! — here’s the same link on the Hibernate site:
    http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping.html#mapping-declaration-compositeid

    Cheers,
    Jim

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: [Closed] Hibernate POJO wiz question – why pojo*Id.java?

You must be logged in to post in the forum log in