dev@glassfish.java.net

Re: NetBeans doesn't import tables with no primary key

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Wed, 02 Aug 2006 10:54:05 -0700

Hi Cheng,

I'm still not sure why the don't want to add PK constraints
if those unique keys work the same way? It won't change anything
in the data.

thanks,
-marina

Cheng Fang wrote:
> Thanks for all the input. I've created a NetBeans issue:
>
> http://www.netbeans.org/issues/show_bug.cgi?id=81716
>
> Cheng
>
>
>
>
> Craig L Russell wrote:
>
>> Hi Cheng,
>>
>> On Aug 1, 2006, at 12:29 PM, Cheng Fang wrote:
>>
>>> Thanks, Gordon. I've posted your reply to the forum. I also tried
>>> this usecase on Toplink/Hibernate + J2SE, and it does work.
>>>
>>> Now the question from the user is, NetBeans 5.5 beta 2 does not
>>> support entity class generation from tables with no primary key. In
>>> the generate-entity-class-from-table wizard, all tables with no
>>> primary key are grayed out.
>>>
>>> Why would NetBeans disable a feature supported by Glassfish, Toplink
>>> and Hiberante? Can we enable it?
>>
>>
>>
>> I was one of the people with input to the original design decision (5
>> years ago) to disallow generation of persistent classes where there
>> was no primary key column in the table. We did not try to guess if
>> the user intended that one of the unique constraints was supposed to
>> map to an identity field.
>>
>> As I understand it, during generation of the class, the wizard needs
>> additional user input or needs to take a guess as to which unique
>> constraint should map to @Id. It's not clear what a rational default
>> should be in the case that there are multiple unique constraints that
>> might be mapped. And since the Id field is immutable after persist,
>> it's not clear that you would have a usable class by mapping such a
>> table.
>>
>> A feature in the wizard to guess the Id of a table without a primary
>> key can be added but wasn't part of the original design specification.
>>
>> I'd suggest filing a feature request in Glassfish/Netbeans so we can
>> track it formally.
>>
>> Regards,
>>
>> Craig
>>
>>>
>>> Cheng
>>>
>>>
>>>
>>>
>>> Gordon Yorke wrote:
>>>
>>>> Hello Cheng,
>>>> If they know which columns correspond to the Unique Index they can
>>>> map these as the PK's in EJB3 even though they are not specified as
>>>> PK's in their tables. These @Id mappings would satisfy the EJB3.0
>>>> requirements but their application would not be required to use
>>>> these PK's if they did not apply. All queries could be JPA queries.
>>>> --Gordon
>>>>
>>>> -----Original Message-----
>>>> From: Cheng.Fang_at_Sun.COM [mailto:Cheng.Fang_at_Sun.COM]On Behalf Of Cheng
>>>> Fang
>>>> Sent: Monday, July 31, 2006 3:30 PM
>>>> To: dev_at_glassfish.dev.java.net
>>>> Subject: primary tables with no primary key supported in EJB 3?
>>>>
>>>>
>>>> Follow-up question for the user: is this supported in Glassfish EJB 3
>>>> (Persistence)?
>>>>
>>>> http://gceclub.sun.com.cn/NASApp/sme/jive/thread.jsp?
>>>> forum=22&thread=39131
>>>>
>>>> The reason he/she is asking this question is, his company used C and
>>>> Informix 7 before, and it has been working pretty well for 7 years.
>>>> They don't know why these tables have no primary key (most only have
>>>> unique index), since original developers have left.
>>>>
>>>> Now they are working on a new project, and evaluating EJB 3
>>>> (persistence) for possible use. They need to use these legacy
>>>> data, but
>>>> don't want change the database structure. They have hundreds of
>>>> tables
>>>> like this and some talbes contain several million records.
>>>>
>>>> In Glassfish EJB 3, is it possible to loosen the validation and allow
>>>> these apps to deploy and run, maybe with some sort of warning? The
>>>> user
>>>> said situations like this is not uncommon. And any advice in general?
>>>>
>>>> Their app deploys and runs fine on Jboss.
>>>>
>>>> Thanks,
>>>>
>>>> Cheng
>>>>
>>>>
>>>> Marina Vatkina wrote:
>>>>
>>>>
>>>>> No, we do not support primary tables without primary keys for CMP
>>>>> 2.1.
>>>>>
>>>>> regards,
>>>>> -marina
>>>>>
>>>>> Cheng Fang wrote:
>>>>>
>>>>>
>>>>>> This user is using ejb 2.1 on SJSAS PE 9. The Student table doesn't
>>>>>> designate a primary key, but in ejb code he uses 'id' as if it was a
>>>>>> primary key. The app failed to deploy on SJSAS 9. But he was able to
>>>>>> deploy and run the same app on JBoss.
>>>>>>
>>>>>> error messages (hope you can tell something from a few keywords)
>>>>>> Deploying application in domain failed; 运行 EJBC 时发生错 误 -- 来自
>>>>>> EJB 编译器的致命错误 -- JDO74025: JDOCodeGenerator: 验 证应用程序
>>>>>> “EJBModule1” 的模块“EJBModule1”中的 CMP Bean“Fhdsckfhz”时捕获异常:
>>>>>> JDO72335: 如果与生 成的类 testsss.FhdsckfhzBean96247497_JDOState
>>>>>> 对应
>>>>>> 的 Bean 的表 fhdsckfhz 被映射为主表, 则它必须有主 键。请选择其它主
>>>>>> 表或
>>>>>> 验证模式文件的内容是否正确。
>>>>>>
>>>>>> Once he specified 'id' as primary key in database table, it deploys
>>>>>> and runs fine. So the question is, does SJSAS 9 ejb 2.x support
>>>>>> tables with no primary key?
>>>>>>
>>>>>> More details are here:
>>>>>> http://gceclub.sun.com.cn/NASApp/sme/jive/thread.jsp?
>>>>>> forum=22&thread=39131
>>>>>>
>>>>>>
>>>>>>
>>>>> -------------------------------------------------------------------- -
>>>>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>>>>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>>>>
>>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>>>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>>
>>
>> Craig Russell
>> clr@apache.org http://db.apache.org/jdo
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>