You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Tony McLay <to...@uk.ibm.com> on 2010/03/18 15:01:46 UTC

Can Class annotations and xml definitions be mixed in the same application - problem with many-to-one foreign key generation

Hello,

Can entities be defined as annotations in a class and in a <mapping-file> 
referenced from a persistence.xml file? (or must you use one or other 
technique?)
We are using openjpa 1.2.1

We have an application where entities have been defined using class 
annotations. However, we have run into a problem where we need to use 
nvarchar types for mssql (multibyte support), and this can be solved by 
creating persistence units defined in a persistence.xml file - these units 
in turn reference the required entities defined in a <mapping-file> - then 
we use a columnDefinition attribute to define the type for mssql. 
Currently, we have just put one entity into the mapping file, and left the 
other entity definitions as class annotations, but for a many-to-one 
element defined in the mapping file entity, the table generated does not 
add a foreign key constraint (that maps to another entity defined as a 
class annotation). 

I want to check if I can avoid putting all the entities in the mapping 
file (bit of a slog) - is this a know issue - I've tried every permutation 
of attributes/elements in the many-to-one element in the xml mapping-file, 
but cannot get a foreign key generated (just generates as a basic column).

Thanks
Tony





Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 
741598. 
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU






Re: Can Class annotations and xml definitions be mixed in the same application - problem with many-to-one foreign key generation

Posted by Tony Mclay <to...@uk.ibm.com>.
Thanks Kevin for the quick & positive response - encouraged me to persevere!

I have now succeeded in combining persistence.xml definitions (to override
db types) and class annotations. Key to this was adding a column-definition
to the join-column of many-to-one relationships (e.g.
column-definition="VARCHAR(50)") in my persistence mapping files - having
done this, the foreign keys are now being generated!

Tony

-- 
View this message in context: http://n2.nabble.com/Can-Class-annotations-and-xml-definitions-be-mixed-in-the-same-application-problem-with-many-to-one-n-tp4757250p4902118.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Can Class annotations and xml definitions be mixed in the same application - problem with many-to-one foreign key generation

Posted by Kevin Sutter <kw...@gmail.com>.
Hi Tony,
Absolutely, annotations and xml definitions can be mixed in the same
application.  Per the spec, the xml definitions rule over the annotations.
This makes sense -- you would want your deployment packaging (xml
definitions) overrule the annotations that your developers insert into the
code.

Kevin

On Thu, Mar 18, 2010 at 9:01 AM, Tony McLay <to...@uk.ibm.com> wrote:

> Hello,
>
> Can entities be defined as annotations in a class and in a <mapping-file>
> referenced from a persistence.xml file? (or must you use one or other
> technique?)
> We are using openjpa 1.2.1
>
> We have an application where entities have been defined using class
> annotations. However, we have run into a problem where we need to use
> nvarchar types for mssql (multibyte support), and this can be solved by
> creating persistence units defined in a persistence.xml file - these units
> in turn reference the required entities defined in a <mapping-file> - then
> we use a columnDefinition attribute to define the type for mssql.
> Currently, we have just put one entity into the mapping file, and left the
> other entity definitions as class annotations, but for a many-to-one
> element defined in the mapping file entity, the table generated does not
> add a foreign key constraint (that maps to another entity defined as a
> class annotation).
>
> I want to check if I can avoid putting all the entities in the mapping
> file (bit of a slog) - is this a know issue - I've tried every permutation
> of attributes/elements in the many-to-one element in the xml mapping-file,
> but cannot get a foreign key generated (just generates as a basic column).
>
> Thanks
> Tony
>
>
>
>
>
> Unless stated otherwise above:
> IBM United Kingdom Limited - Registered in England and Wales with number
> 741598.
> Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
>
>
>
>
>
>