- This topic has 6 replies, 2 voices, and was last updated 19 years, 2 months ago by
jimbethancourt.
-
AuthorPosts
-
jimbethancourtMemberHi 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 eithere.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,
JimApril 19, 2006 at 5:04 pm #250775
Riyad KallaMemberJim,
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…April 19, 2006 at 5:20 pm #250780
jimbethancourtMemberHi 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]
GOCREATE 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]
GOOf note — my manager had the same thing happen to him with another POJO he generated with the 4.1.1 hibernate mapper
Thanks,
JimApril 19, 2006 at 5:30 pm #250781
jimbethancourtMemberCould 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,
JimApril 19, 2006 at 6:43 pm #250788
jimbethancourtMemberI 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-compositeidSolution: *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,
JimApril 19, 2006 at 8:45 pm #250799
Riyad KallaMemberAhh, great catch Jim, thanks for following up.
April 20, 2006 at 9:09 am #250818
jimbethancourtMemberOops! — here’s the same link on the Hibernate site:
http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping.html#mapping-declaration-compositeidCheers,
Jim -
AuthorPosts