mysql @Column unique

2019-11-04 Thread Matthew Broadhead
i am using value="buildSchema(ForeignKeys=true)" /> to generate the MySQL tables 
based on the entities.


however @Column(unique = true) does not seem to have flaged the field as 
unique


log info about current transaction

2019-05-14 Thread Matthew Broadhead
i have a strange case at the moment which i have not bumped into 
before.  EventController.deleteEvent looks like

public void deleteEvent(File file, CEvent event) {
    if (event.getSubType().equals("note")) {
            Note note = noteController.selectNote(file, 
event.getEventId());

            file.getNotes().remove(note);
        } else if (event.getSubType().equals("event")) {
            Event event_ = selectEvent(file, event.getEventId());
            file.getEvents().remove(event_);
        } else if (event.getSubType().equals("document")) {
            documentController.deleteDocument(event.getEventId());
        } else if (event.getSubType().equals("upload")) {
            documentController.deleteUploadView(event.getEventId());
        }
...

DocumentController.deleteDocument looks like
public void deleteDocument(int documentId) {
        Document document = documentDb.selectDocument(documentId);
        if (document != null) {
            document.setArchived(new Date());
            documentDb.flush();
        }
    }

removing events and notes works fine but deleting a document results in 
"org.apache.openjpa.persistence.TransactionRequiredException: Can only 
perform operation while a transaction is active."


everything uses the same entitymanager.  is there any way to output the 
current transaction details to see at what point the transaction is lost?


 
org.apache.openjpa.persistence.TransactionRequiredException: Can only 
perform operation while a transaction is active.
    at 
org.apache.openjpa.kernel.BrokerImpl.assertActiveTransaction(BrokerImpl.java:4729)
    at 
org.apache.openjpa.kernel.DelegatingBroker.assertActiveTransaction(DelegatingBroker.java:1385)
    at 
org.apache.openjpa.persistence.EntityManagerImpl.flush(EntityManagerImpl.java:663)
    at 
org.apache.webbeans.custom.persistence.EntityManager$$OwbNormalScopeProxy0.flush(javax/persistence/EntityManager.java)
    at 
uk.me.kissy.database.db.document.DocumentDb.flush(DocumentDb.java:120)
    at 
uk.me.kissy.database.db.document.DocumentDb$$OwbNormalScopeProxy0.flush(uk/me/kissy/database/db/document/DocumentDb.java)
    at 
uk.me.kissy.database.controllers.document.DocumentController.deleteDocument(DocumentController.java:769)
    at 
uk.me.kissy.database.controllers.document.DocumentController$$OwbNormalScopeProxy0.deleteDocument(uk/me/kissy/database/controllers/document/DocumentController.java)
    at 
uk.me.kissy.database.controllers.file.EventController.deleteEvent(EventController.java:94)
    at 
uk.me.kissy.database.controllers.file.EventController$$OwbNormalScopeProxy0.deleteEvent(uk/me/kissy/database/controllers/file/EventController.java)

    at uk.me.kissy.file.beans.EventsBean.deleteEvent(EventsBean.java:228)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


hibernate @JoinFormula

2019-03-21 Thread Matthew Broadhead

is there an OpenJPA equivalent of Hibernate's @JoinFormula annotation?


caching a query

2019-03-17 Thread Matthew Broadhead
i have a query that takes around 8 seconds and i want cache it.  i 
searched for caching a jpa query and came across query cache 
https://openjpa.apache.org/builds/2.4.1/apache-openjpa/docs/ref_guide_caching.html#ref_guide_cache_query.

i tried pinning the query but it made no difference.
i also tried the hints javax.persistence.cache.retrieveMode and 
javax.persistence.cache.storeMode but didn't see any difference there 
either.

also tried adding @Cacheable to the Entity in question



Re: openjpa indexes

2019-03-02 Thread Matthew Broadhead
Thanks,  I am glad you are looking into the issue.  I don't really know 
much about the internals of OpenJpa. The code you created looks sensible


On 01/03/2019 11:41, Maxim Solodovnik wrote:

I have created JIRA to track the status:
https://issues.apache.org/jira/browse/OPENJPA-2777
Will try to add some tests and will ask for review/verification :)

On Tue, 26 Feb 2019 at 09:15, Maxim Solodovnik  wrote:

I have started work on this

Could you please take a look? Is it the step in right direction?
https://github.com/apache/openjpa/compare/javax-index?expand=1

On Mon, 25 Feb 2019 at 22:26, Maxim Solodovnik  wrote:

Additional suspicious annotations are:

org.apache.openjpa.persistence.jdbc.Unique  ( vs.
javax.persistence.UniqueConstraint)
org.apache.openjpa.persistence.jdbc.ForeignKey ( vs.
javax.persistence.ForeignKey)

maybe some more
Maybe it worth to be dropped and replaced with annotations from
javax.persistence.* ?

On Mon, 25 Feb 2019 at 22:10, Maxim Solodovnik  wrote:

Hello All,

I'm still debugging the code trying to understand what is going on in the code
It seems indices are being created for foreign keys only

Can it be caused by the fact OpenJPA still has it's own annotation for
indices org.apache.openjpa.persistence.jdbc.Index ?

Will try to debug also `DBDictionary#getCreateIndexSQL`

On Thu, 3 Jan 2019 at 02:12, Mark Struberg  wrote:

  The generator happens in the MappingTool. This is the top-level.Probably the 
best guess is to set a breakpoint in  DBDictionary#getCreateIndexSQLThe 
DBDictionary (and it's respecive subclasses) is where all the adopting to 
different databases happens.
LieGrue,strub

 On Tuesday, 18 December 2018, 03:53:51 CET, Maxim Solodovnik 
 wrote:

  Unfortunately I was unable to find where this magic happens :(
can someone from devs can point me to the right direction?

On Sat, 15 Dec 2018 at 16:58, Matthew Broadhead
 wrote:


i am using mysql

On 15/12/2018 09:35, Maxim Solodovnik wrote:

Indicies seems to be auto-created on
@Id, @PrimaryKeyJoinColumn and @JoinColumn

just have tested with MySql DB Index seems not being created
will try to debug


On Thu, 13 Dec 2018 at 23:33, Matthew Broadhead
 wrote:


i saw a similar example but was hoping the index could be automatically
created.  some indexes are automatically created but seeingly not

others.

i tried the annotations as in the example and the index is never
created.  here is what i have added to my class
@Entity
@Table(name = "billentry", indexes = {
  @Index(name = "I_BLLNTRY_SECTION", columnList =
"BILLSECTION_ID", unique = false),
  @Index(name = "I_BLLNTRY_BILLTEMPLATEENTRY", columnList =
"btentryid", unique = false) })
public class BillEntry implements Serializable {
  private static final long serialVersionUID = 1L;

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  @Version
  private Long version;

  @ManyToOne
  private BillSection billSection;

  @ManyToOne
  @Column(name = "btentryid")
  private BillTemplateEntry billTemplateEntry;

On 12/12/2018 02:34, Maxim Solodovnik wrote:

This might help for the latest OpenJpa (it should have partial 2.1
compatibility)
https://stackoverflow.com/a/22658951/3571661

On Wed, 12 Dec 2018 at 01:17, Matthew Broadhead
 wrote:


recently had an application running slowly and had to manually add an
index.  but openjpa seemed to create all the other indexes

automatically.

my structure was like
Bill
has a collection of
BillMoney
has a collection of
BillSection
has a collection of
BillEntry

BillMoney was automatically created with index I_BLLMONY_BILL which
related to the Bill id
BillSection was automatically created with index I_BLLSCTN_BILLMONEY
which related to the BillMoney section
But BillEntry did not have an index.

BillEntry was a pre existing table so could that have something to do
with it?  is there any way to force indexes to be created?




--
WBR
Maxim aka solomax




--
WBR
Maxim aka solomax



--
WBR
Maxim aka solomax



--
WBR
Maxim aka solomax







Re: using different datasource during junit tests

2019-02-14 Thread Matthew Broadhead

thanks Francesco, i don't use spring currently so it may not work in my case

i often consider diving into spring when i see
a) how many positions require it in the job market
b) how many web tutorials mention it

On 13/02/2019 17:10, Francesco Chicchiriccò wrote:

On 13/02/19 15:04, Matthew Broadhead wrote:
i am trying to test some business logic that depends heavily on the 
results of calls to entitymanager. i would like to keep the 
persistence.xml exactly as it is in the main project but basically 
load in a different database underneath.  is there a way to 
initialise the entitymanager and point it to a development database 
for the duration of the tests?


Hi Matthew,
I normally do as you require above, but with some Spring ORM support, 
not sure it fits with your scenario; if so, I can point you to some 
working samples.


Regards.





using different datasource during junit tests

2019-02-13 Thread Matthew Broadhead
i am trying to test some business logic that depends heavily on the 
results of calls to entitymanager.  i would like to keep the 
persistence.xml exactly as it is in the main project but basically load 
in a different database underneath.  is there a way to initialise the 
entitymanager and point it to a development database for the duration of 
the tests?


cascade

2019-01-16 Thread Matthew Broadhead
i just messed up a load of data by copying and pasting a @OneToMany 
annotation which had a cascade defined without realising.  is it 
possible to define cascade relationships separately in an xml file? like 
orm.xml or whatever.  or will that stop other annotations from working?


Re: [DISCUSS] end support for OpenJPA-1.x?

2019-01-07 Thread Matthew Broadhead
that sounds sensible.  although i only started using OpenJPA recently so 
not sure how many are still depending on 1.x.  are any of the tickets 
relevant to later versions and having high watch counts?


On 07/01/2019 23:05, Mark Struberg wrote:

hi folks!

I think the times of the 1.x rage of OpenJPA is over.
This is our JPA-1.0 branch (JavaEE5).
Wdyt about declaring it EOL and closing all the tickets for it?

Of course OpenJPA-2.x and 3.x will continue to be active!

LieGrue,
strub




Re: deleting openjpa_sequence_table

2019-01-06 Thread Matthew Broadhead

hi Mark,

there are no tables conflicting between the databases.  i want to 
simplify by moving tables from 3 databases into 1.  so merging the data 
is not a problem.


that is a good hint about openjpa.Sequence.  at the moment it seems to 
just use one sequence for all the tables.  can i add that to my 
persistence.xml at this stage?  if i delete the openjpa_sequence_table 
will it recalculate the highest index for each table?


On 05/01/2019 22:16, Mark Struberg wrote:

Hi Matthew!

As Craig already explained they contain the hightest value for a specified 
index.
Of course only if no Database Sequence got used!
The reason to use this over a Sequence is to have a database independent 
counter which is fully portable.

There are also multiple 'modes' for the sequence to operate!
I personally prefer the counter by table.

In your persistence.xml you might probably have something like the following in your 
 section:



openjpa.Sequence determines the strategy to use plus the details. 'class-table' 
will create 1 row per @Entity basically.

You can read more over here:
https://openjpa.apache.org/builds/3.0.0/apache-openjpa/docs/ref_guide_sequence.html


So in hindsight dealing with the openjpa_sequence values might be your least 
problematic issue.
The more problematic one might be that you have to re-assign new primary keys 
to your migrated data.

Consider you have an @Entity Customer. Then both or your databases to merge 
might have a Customer with the id=1. And 2 customers with id=2, etc.
That means merging them together will create a unique key violation.

One strategy is to leave one db as is and update the other one.
If you e.g. have 18572 customers in database_A. Then you could update all your 
customers in database_B to be 1+id. Means your customer with id=1 in 
database_B will get id=11, etc. And of course you will have to update all 
the 1:n referencing tables as well. So e.g. update all Address entries to have 
a customerid=customerid+10;
You might need to drop/disable all foreign-key indexes before you start doing 
this update and then activate them again after all is done.
And of course this can only be done while there is no moving target. That means 
you have to stop operation on your db. If this is not possible then you might 
want to do this with 'filtered tx-logs'. But that is WAY more effort...

After that you can merge both without a conflict.

Do others have a better idea?

LieGrue,
strub




Am 05.01.2019 um 01:04 schrieb Craig Russell :

It might be best to inspect the tables and merge them when you merge the 
databases. IIRC they hold the highest keys that have been used and simply 
dropping them might introduce errors.

Craig


On Jan 4, 2019, at 5:40 AM, Matthew Broadhead 
 wrote:

i am about to merge a few databases.  each database has an 
openjpa_sequence_table.  do i just drop these tables?

Craig L Russell
c...@apache.org





deleting openjpa_sequence_table

2019-01-04 Thread Matthew Broadhead
i am about to merge a few databases.  each database has an 
openjpa_sequence_table.  do i just drop these tables?


Re: openjpa indexes

2018-12-15 Thread Matthew Broadhead

i am using mysql

On 15/12/2018 09:35, Maxim Solodovnik wrote:

Indicies seems to be auto-created on
@Id, @PrimaryKeyJoinColumn and @JoinColumn

just have tested with MySql DB Index seems not being created
will try to debug


On Thu, 13 Dec 2018 at 23:33, Matthew Broadhead
 wrote:


i saw a similar example but was hoping the index could be automatically
created.  some indexes are automatically created but seeingly not others.
i tried the annotations as in the example and the index is never
created.  here is what i have added to my class
@Entity
@Table(name = "billentry", indexes = {
  @Index(name = "I_BLLNTRY_SECTION", columnList =
"BILLSECTION_ID", unique = false),
  @Index(name = "I_BLLNTRY_BILLTEMPLATEENTRY", columnList =
"btentryid", unique = false) })
public class BillEntry implements Serializable {
  private static final long serialVersionUID = 1L;

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  @Version
  private Long version;

  @ManyToOne
  private BillSection billSection;

  @ManyToOne
  @Column(name = "btentryid")
  private BillTemplateEntry billTemplateEntry;

On 12/12/2018 02:34, Maxim Solodovnik wrote:

This might help for the latest OpenJpa (it should have partial 2.1
compatibility)
https://stackoverflow.com/a/22658951/3571661

On Wed, 12 Dec 2018 at 01:17, Matthew Broadhead
 wrote:


recently had an application running slowly and had to manually add an
index.  but openjpa seemed to create all the other indexes

automatically.

my structure was like
Bill
has a collection of
BillMoney
has a collection of
BillSection
has a collection of
BillEntry

BillMoney was automatically created with index I_BLLMONY_BILL which
related to the Bill id
BillSection was automatically created with index I_BLLSCTN_BILLMONEY
which related to the BillMoney section
But BillEntry did not have an index.

BillEntry was a pre existing table so could that have something to do
with it?  is there any way to force indexes to be created?







Re: openjpa indexes

2018-12-13 Thread Matthew Broadhead
i saw a similar example but was hoping the index could be automatically 
created.  some indexes are automatically created but seeingly not others.
i tried the annotations as in the example and the index is never 
created.  here is what i have added to my class

@Entity
@Table(name = "billentry", indexes = {
        @Index(name = "I_BLLNTRY_SECTION", columnList = 
"BILLSECTION_ID", unique = false),
        @Index(name = "I_BLLNTRY_BILLTEMPLATEENTRY", columnList = 
"btentryid", unique = false) })

public class BillEntry implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Version
    private Long version;

    @ManyToOne
    private BillSection billSection;

    @ManyToOne
    @Column(name = "btentryid")
    private BillTemplateEntry billTemplateEntry;

On 12/12/2018 02:34, Maxim Solodovnik wrote:

This might help for the latest OpenJpa (it should have partial 2.1
compatibility)
https://stackoverflow.com/a/22658951/3571661

On Wed, 12 Dec 2018 at 01:17, Matthew Broadhead
 wrote:


recently had an application running slowly and had to manually add an
index.  but openjpa seemed to create all the other indexes automatically.
my structure was like
Bill
has a collection of
BillMoney
has a collection of
BillSection
has a collection of
BillEntry

BillMoney was automatically created with index I_BLLMONY_BILL which
related to the Bill id
BillSection was automatically created with index I_BLLSCTN_BILLMONEY
which related to the BillMoney section
But BillEntry did not have an index.

BillEntry was a pre existing table so could that have something to do
with it?  is there any way to force indexes to be created?







openjpa indexes

2018-12-11 Thread Matthew Broadhead
recently had an application running slowly and had to manually add an 
index.  but openjpa seemed to create all the other indexes automatically.

my structure was like
Bill
has a collection of
BillMoney
has a collection of
BillSection
has a collection of
BillEntry

BillMoney was automatically created with index I_BLLMONY_BILL which 
related to the Bill id
BillSection was automatically created with index I_BLLSCTN_BILLMONEY 
which related to the BillMoney section

But BillEntry did not have an index.

BillEntry was a pre existing table so could that have something to do 
with it?  is there any way to force indexes to be created?


Re: Primary key string ids are stripped

2018-10-26 Thread Matthew Broadhead
can you give a small example?  do you mean when the field annotated @Id 
is a String then find returns null?


On 25/10/2018 02:34, Pawel Veselov wrote:

Hello.

I just found out, the hard way, that OpenJPA strips the string entity
IDs when doing find().
It doesn't strip those values when saving entities with corresponding
primary keys.
Is there a particular reason for this? It sounds weird to create an
entity with primary key "0\t", but then not be able to find it right
after

Thank you,
   Pawel.




Re: NPE on MapKey maps

2018-09-08 Thread Matthew Broadhead

sorry i missed the point about the mapkey.

On 08/09/18 10:26, Matthew Broadhead wrote:

If it is set to cascade then this should work?
MapKeyParent parent = new MapKeyParent();
parent.setChildren(new ArrayList<>());
MapKeyChild child = new MapKeyChild();
child.setParent(parent);
parent.getChildren().add(child);
em.persist(parent);
em.flush();


On 08/09/18 02:42, Pawel Veselov wrote:

Hello.

I ran into this problem, and I'm not sure what the right answer is.
Consider just two entities (I've gutted them to the pieces that are
relevant, I tried this on corresponding classes in
org.apache.openjpa.persistence.relations package,
openjpa-persistence-jdbc module):

public class MapKeyParent implements Serializable {
 @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch =
FetchType.EAGER)
 @MapKey(name = "mapKey")
 private Map children;
}
public class MapKeyChild implements Serializable {
 @ManyToOne @JoinColumn private MapKeyParent parent;
}

Creating the entities separately, and flushing them causes an NPE
(https://pastebin.com/StN604Hg):

 MapKeyParent parent = new MapKeyParent();
 MapKeyChild child = new MapKeyChild();
 child.setParent(parent);
 em.persist(parent);
 em.persist(child);
 em.flush();

The NPE is obviously because parent.children is null. But should this
be considered a problem? Is there a rule that says that I have to
reference children in the corresponding collections/maps (I never had
to do it before)? If it is not required, how can this be fixed?

I can't quite understand what is the point of
RelationFieldStrategy.setMapKey() method. It seems that it may not do
well if map, or the key is null. Also, I'm rather bothered by the fact
that map key is searched in the map by iterating over the map values,
and even it's not needed (i.e. when key is not embedded and strategy
is not HandlerRelationMapTableFieldStrategy).

An obvious "fix" for me, is to either add the object to children map,
or at least have the map empty by the time flush() is called. I don't
see any adverse effects on sending the data to the storage.

Thank you,
   Pawel.






Re: NPE on MapKey maps

2018-09-08 Thread Matthew Broadhead

If it is set to cascade then this should work?
MapKeyParent parent = new MapKeyParent();
parent.setChildren(new ArrayList<>());
MapKeyChild child = new MapKeyChild();
child.setParent(parent);
parent.getChildren().add(child);
em.persist(parent);
em.flush();


On 08/09/18 02:42, Pawel Veselov wrote:

Hello.

I ran into this problem, and I'm not sure what the right answer is.
Consider just two entities (I've gutted them to the pieces that are
relevant, I tried this on corresponding classes in
org.apache.openjpa.persistence.relations package,
openjpa-persistence-jdbc module):

public class MapKeyParent implements Serializable {
 @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch =
FetchType.EAGER)
 @MapKey(name = "mapKey")
 private Map children;
}
public class MapKeyChild implements Serializable {
 @ManyToOne @JoinColumn private MapKeyParent parent;
}

Creating the entities separately, and flushing them causes an NPE
(https://pastebin.com/StN604Hg):

 MapKeyParent parent = new MapKeyParent();
 MapKeyChild child = new MapKeyChild();
 child.setParent(parent);
 em.persist(parent);
 em.persist(child);
 em.flush();

The NPE is obviously because parent.children is null. But should this
be considered a problem? Is there a rule that says that I have to
reference children in the corresponding collections/maps (I never had
to do it before)? If it is not required, how can this be fixed?

I can't quite understand what is the point of
RelationFieldStrategy.setMapKey() method. It seems that it may not do
well if map, or the key is null. Also, I'm rather bothered by the fact
that map key is searched in the map by iterating over the map values,
and even it's not needed (i.e. when key is not embedded and strategy
is not HandlerRelationMapTableFieldStrategy).

An obvious "fix" for me, is to either add the object to children map,
or at least have the map empty by the time flush() is called. I don't
see any adverse effects on sending the data to the storage.

Thank you,
   Pawel.




criteriabuilder predicate version

2018-08-21 Thread Matthew Broadhead

is it not possible to query the @Version field using criteriabuilder?

i am trying this and it is not returning any results
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery(Document.class);
Root document = cq.from(Document.class);
List predicateList = new ArrayList<>();
predicateList.add(cb.isNull(document.get("version")));
cq.select(document);
cq.where(cb.and(predicateList.toArray(new 
Predicate[predicateList.size()])));

cq.distinct(true);
cq.orderBy(cb.desc(document.get("id")));
TypedQuery query = em.createQuery(cq);
query.setMaxResults(250);
List list = query.getResultList();
return list;

if i switch to another Long field which supports null then it works fine


Re: clone object

2018-07-27 Thread Matthew Broadhead
i have a complicated object with a large number of children, each child 
possibly having their own large number of children.  what would be great 
in OpenJPA is if you could, say, detach an object and run a command 
which would null all @Id and @Version fields in the detached Object and 
all its descendants.  i suppose it has to be done manually though...


On 27/07/18 15:52, Albert Lee wrote:

If the java object implements Serializable or Clonable, you can
writeObject/readObject to clone to a new entity.  The new object will be
detached and you can reset the id and version as you wish.


On Fri, Jul 27, 2018 at 8:39 AM, Matthew Broadhead <
matthew.broadh...@nbmlaw.co.uk.invalid> wrote:


i don't think it would clear the id and version fields?  do you mean using
SerializationUtils clone?
https://commons.apache.org/proper/commons-lang/apidocs/org/
apache/commons/lang3/SerializationUtils.html


On 27/07/18 15:09, Albert Lee wrote:


If the entity is serializable have you try writing it out and read it back
to a new object?

On Fri, Jul 27, 2018, 6:05 AM Matthew Broadhead
 wrote:

is there a way to deep clone a JPA object automatically?  i.e. to copy

all the parameters and children but clear the id and version fields?

i saw that it is possible to do em.detach(object); and then reset the id
and version but by the time i have done that i may as well have written
a full copy function.








clone object

2018-07-27 Thread Matthew Broadhead
is there a way to deep clone a JPA object automatically?  i.e. to copy 
all the parameters and children but clear the id and version fields?


i saw that it is possible to do em.detach(object); and then reset the id 
and version but by the time i have done that i may as well have written 
a full copy function.


Re: Escape default value on CREATE TABLE

2018-06-14 Thread Matthew Broadhead

this says you have to hack column definition
https://stackoverflow.com/questions/197045/setting-default-values-for-columns-in-jpa

maybe you could try surrounding with single quotes, like
cName.setDefault("'O,K'");

On 14/06/18 10:34, Matthew Broadhead wrote:

did you try cName.setDefaultString("O,K");
?

On 14/06/18 09:29, Yves PIEL wrote:

Thank you Matthew,

I know how to set default value as you can see in my example
cName.setDefault("O,K");
but it is not escape : "na-me" VARCHAR(255) DEFAULT O,K NOT NULL,
Should be : "na-me" VARCHAR(255) DEFAULT "O,K" NOT NULL,
isn't it ?

Regards

On 13 June 2018 at 19:39, Matthew Broadhead <
matthew.broadh...@nbmlaw.co.uk.invalid> wrote:


have you tried setDefaultString?
also this might be the source code here https://apache.googlesource.co
m/openjpa/+/295576ffb0080106de70cc4caf23ab38d59cf56a/
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java


On 13/06/18 12:51, Yves PIEL wrote:


Hello Matthew,

Thanks for your answer.

My use case is really to generate SQL queries programmatically, as my
example shows, not from java entities.

Regards,
Yves

On 13 June 2018 at 12:18, Matthew Broadhead <
matthew.broadh...@nbmlaw.co.uk>
wrote:

i don't know your use case but i generate the tables automatically 
from

the java entities by setting the SynchroniseMappings property in
persistence.xml, e.g.

http://xmlns.jcp.org/xml/ns/persistence;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd;>
  
myDb
com.example.entities.jpa.Entity1
com.example.entities.jpa.Entity2
  
  
  
  


an example entity might be:
package com.example.entities.jpa;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Version;

@Entity
public class Entity1 implements Serializable {
  private static final long serialVersionUID = 1L;

  @Id
  private Long id;

  @Version
  private Long version;

  @Column(length = 255)
  private String name;

  ...getters setters
}

and you could just set the default when you initialise the Entity? 
like

Entity1 entity1 = new Entity1();
entity1.setName("O,K");


On 12/06/18 15:21, Yves PIEL wrote:

Hi,
I try to use JPA to generate CREATE TABLE statements.All works 
fine but

default values of VARCHAR.

For example, I add a VARCHAR column with default value with :

DBIdentifier name = DBIdentifier.newColumn("na-me");
Column cName = table.addColumn(name);
cName.setType(Types.VARCHAR);
cName.setNotNull(true);
cName.setSize(255);
cName.setDefault("O,K");

And the generated code is:

DB => CREATE TABLE "My-schema".MaTable (id1 INTEGER NOT NULL, id2
VARCHAR(500) NOT NULL, "na-me" VARCHAR(255) DEFAULT O,K NOT NULL, 
âge
TINYINT DEFAULT 20, salary DECIMAL, CONSTRAINT idkeys PRIMARY KEY 
(id1,

id2))


'O,K' will corrupt my SQL query. How can I force the escape of 
default

values ?

Regards,
Yves









Re: Escape default value on CREATE TABLE

2018-06-14 Thread Matthew Broadhead

did you try cName.setDefaultString("O,K");
?

On 14/06/18 09:29, Yves PIEL wrote:

Thank you Matthew,

I know how to set default value as you can see in my example
cName.setDefault("O,K");
but it is not escape : "na-me" VARCHAR(255) DEFAULT O,K NOT NULL,
Should be : "na-me" VARCHAR(255) DEFAULT "O,K" NOT NULL,
isn't it ?

Regards

On 13 June 2018 at 19:39, Matthew Broadhead <
matthew.broadh...@nbmlaw.co.uk.invalid> wrote:


have you tried setDefaultString?
also this might be the source code here https://apache.googlesource.co
m/openjpa/+/295576ffb0080106de70cc4caf23ab38d59cf56a/
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java


On 13/06/18 12:51, Yves PIEL wrote:


Hello Matthew,

Thanks for your answer.

My use case is really to generate SQL queries programmatically, as my
example shows, not from java entities.

Regards,
Yves

On 13 June 2018 at 12:18, Matthew Broadhead <
matthew.broadh...@nbmlaw.co.uk>
wrote:

i don't know your use case but i generate the tables automatically from

the java entities by setting the SynchroniseMappings property in
persistence.xml, e.g.

http://xmlns.jcp.org/xml/ns/persistence;
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd;>
  
  myDb
  com.example.entities.jpa.Entity1
  com.example.entities.jpa.Entity2
  
  
  
  


an example entity might be:
package com.example.entities.jpa;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Version;

@Entity
public class Entity1 implements Serializable {
  private static final long serialVersionUID = 1L;

  @Id
  private Long id;

  @Version
  private Long version;

  @Column(length = 255)
  private String name;

  ...getters setters
}

and you could just set the default when you initialise the Entity? like
Entity1 entity1 = new Entity1();
entity1.setName("O,K");


On 12/06/18 15:21, Yves PIEL wrote:

Hi,

I try to use JPA to generate CREATE TABLE statements.All works fine but
default values of VARCHAR.

For example, I add a VARCHAR column with default value with :

DBIdentifier name = DBIdentifier.newColumn("na-me");
Column cName = table.addColumn(name);
cName.setType(Types.VARCHAR);
cName.setNotNull(true);
cName.setSize(255);
cName.setDefault("O,K");

And the generated code is:

DB => CREATE TABLE "My-schema".MaTable (id1 INTEGER NOT NULL, id2
VARCHAR(500) NOT NULL, "na-me" VARCHAR(255) DEFAULT O,K NOT NULL, âge
TINYINT DEFAULT 20, salary DECIMAL, CONSTRAINT idkeys PRIMARY KEY (id1,
id2))


'O,K' will corrupt my SQL query. How can I force the escape of default
values ?

Regards,
Yves







Re: Escape default value on CREATE TABLE

2018-06-13 Thread Matthew Broadhead

have you tried setDefaultString?
also this might be the source code here 
https://apache.googlesource.com/openjpa/+/295576ffb0080106de70cc4caf23ab38d59cf56a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java


On 13/06/18 12:51, Yves PIEL wrote:

Hello Matthew,

Thanks for your answer.

My use case is really to generate SQL queries programmatically, as my
example shows, not from java entities.

Regards,
Yves

On 13 June 2018 at 12:18, Matthew Broadhead 
wrote:


i don't know your use case but i generate the tables automatically from
the java entities by setting the SynchroniseMappings property in
persistence.xml, e.g.

http://xmlns.jcp.org/xml/ns/persistence;
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd;>
 
 myDb
 com.example.entities.jpa.Entity1
 com.example.entities.jpa.Entity2
 
 
 
 


an example entity might be:
package com.example.entities.jpa;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Version;

@Entity
public class Entity1 implements Serializable {
 private static final long serialVersionUID = 1L;

 @Id
 private Long id;

 @Version
 private Long version;

 @Column(length = 255)
 private String name;

 ...getters setters
}

and you could just set the default when you initialise the Entity? like
Entity1 entity1 = new Entity1();
entity1.setName("O,K");


On 12/06/18 15:21, Yves PIEL wrote:


Hi,

I try to use JPA to generate CREATE TABLE statements.All works fine but
default values of VARCHAR.

For example, I add a VARCHAR column with default value with :

DBIdentifier name = DBIdentifier.newColumn("na-me");
Column cName = table.addColumn(name);
cName.setType(Types.VARCHAR);
cName.setNotNull(true);
cName.setSize(255);
cName.setDefault("O,K");

And the generated code is:

DB => CREATE TABLE "My-schema".MaTable (id1 INTEGER NOT NULL, id2
VARCHAR(500) NOT NULL, "na-me" VARCHAR(255) DEFAULT O,K NOT NULL, âge
TINYINT DEFAULT 20, salary DECIMAL, CONSTRAINT idkeys PRIMARY KEY (id1,
id2))


'O,K' will corrupt my SQL query. How can I force the escape of default
values ?

Regards,
Yves






Re: Escape default value on CREATE TABLE

2018-06-13 Thread Matthew Broadhead
i don't know your use case but i generate the tables automatically from 
the java entities by setting the SynchroniseMappings property in 
persistence.xml, e.g.


http://xmlns.jcp.org/xml/ns/persistence;
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence 
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd;>

    
        myDb
        com.example.entities.jpa.Entity1
        com.example.entities.jpa.Entity2
        
            
        
    


an example entity might be:
package com.example.entities.jpa;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Version;

@Entity
public class Entity1 implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    private Long id;

    @Version
    private Long version;

    @Column(length = 255)
    private String name;

    ...getters setters
}

and you could just set the default when you initialise the Entity? like
Entity1 entity1 = new Entity1();
entity1.setName("O,K");

On 12/06/18 15:21, Yves PIEL wrote:

Hi,

I try to use JPA to generate CREATE TABLE statements.All works fine but
default values of VARCHAR.

For example, I add a VARCHAR column with default value with :

DBIdentifier name = DBIdentifier.newColumn("na-me");
Column cName = table.addColumn(name);
cName.setType(Types.VARCHAR);
cName.setNotNull(true);
cName.setSize(255);
cName.setDefault("O,K");

And the generated code is:

DB => CREATE TABLE "My-schema".MaTable (id1 INTEGER NOT NULL, id2
VARCHAR(500) NOT NULL, "na-me" VARCHAR(255) DEFAULT O,K NOT NULL, âge
TINYINT DEFAULT 20, salary DECIMAL, CONSTRAINT idkeys PRIMARY KEY (id1,
id2))


'O,K' will corrupt my SQL query. How can I force the escape of default
values ?

Regards,
Yves





Re: reserved words and table names

2018-05-11 Thread Matthew Broadhead
you may be right.  i just tried delimited identifiers but it tries to 
add already existing fields


https://stackoverflow.com/questions/6791882/jpa-database-delimiters?utm_medium=organic_source=google_rich_qa_campaign=google_rich_qa

now i might just go with @Table(name = "ConditionZ")


On 11/05/18 16:48, Sean McDowell wrote:
Hi -- I tried to enable quoting in OpenJPA to deal with reserved 
keywords in MySQL.


The feature seems very buggy and didn't work. I would recommend just 
avoiding keywords.



Sean



From: Matthew Broadhead <matthew.broadh...@nbmlaw.co.uk>
To: users@openjpa.apache.org
Date: 11/05/2018 10:41 AM
Subject: reserved words and table names




i am trying to create a table called Condition but i get
javax.el.ELException: javax.enterprise.inject.CreationException:
org.apache.openjpa.lib.jdbc.ReportingSQLException: You have an error in
your SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near 'Condition

condition is a reserved word in MySQL.  is there a way to tell OpenJPA
to surround table and column names with backticks in queries? i though
it would do that by default








Re: reserved words and table names

2018-05-11 Thread Matthew Broadhead

in hibernate it is hibernate.globally_quoted_identifiers


On 11/05/18 16:41, Matthew Broadhead wrote:
i am trying to create a table called Condition but i get 
javax.el.ELException: javax.enterprise.inject.CreationException: 
org.apache.openjpa.lib.jdbc.ReportingSQLException: You have an error 
in your SQL syntax; check the manual that corresponds to your MySQL 
server version for the right syntax to use near 'Condition


condition is a reserved word in MySQL.  is there a way to tell OpenJPA 
to surround table and column names with backticks in queries?  i 
though it would do that by default






reserved words and table names

2018-05-11 Thread Matthew Broadhead
i am trying to create a table called Condition but i get 
javax.el.ELException: javax.enterprise.inject.CreationException: 
org.apache.openjpa.lib.jdbc.ReportingSQLException: You have an error in 
your SQL syntax; check the manual that corresponds to your MySQL server 
version for the right syntax to use near 'Condition


condition is a reserved word in MySQL.  is there a way to tell OpenJPA 
to surround table and column names with backticks in queries?  i though 
it would do that by default




Re: More test failures - JPA spec overwritten

2018-04-11 Thread Matthew Broadhead

i ran
svn checkout http://svn.apache.org/repos/asf/openjpa/tags/2.4.2/ 
openjpa-2.4.2

cd openjpa-2.4.2
mvn install
and it built first time without errors

On 09/04/2018 23:43, Pawel Veselov wrote:

On Mon, Apr 9, 2018 at 5:01 PM, Matthew Broadhead
<matthew.broadh...@nbmlaw.co.uk> wrote:

The enhancer version of the enhanced classes is 2, but the enhancer is
1674154, which matches the SVN revision of the enhancer, and I believe
that's what it should be. I don't know where it gets the 2 from.

the latest version isn't 2.4.2 is it?  i thought that was an old version.  i
just checked out revision 1828727.  how do you know which revision is 2.4.2?
i checked this http://openjpa.apache.org/building.html and didn't see
anything

It's 2.4.2 because I checked out
http://svn.apache.org/repos/asf/openjpa/tags/2.4.2. 2.4.2 is at
1828187
The revision for the enhancer version is taken from the SVN revision
of the enhancer, not the workspace.
Enhancer is at 
openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java,
and its latest revision, from 2.4.2 PoV is 1674154




Re: More test failures - JPA spec overwritten

2018-04-09 Thread Matthew Broadhead
the latest version isn't 2.4.2 is it?  i thought that was an old 
version.  i just checked out revision 1828727.  how do you know which 
revision is 2.4.2?
i checked this http://openjpa.apache.org/building.html and didn't see 
anything



On 09/04/2018 02:16, Pawel Veselov wrote:

On Sun, Apr 8, 2018 at 5:22 PM, Pawel Veselov  wrote:

Trying to run more tests on 2.4.2. My first compilation was
successful, but now there is another phantom exception that I have no
clue how to resolve. Any help would be appreciated. I haven't made any
changes anywhere that should affect this...

I don't know where the JPA specification is set, or where, or what
file, is it coming from.

OK, this was just me panicking. That trace was an expected failure.
The only problem that I don't quite understand that I have left during
running tests is: https://pastebin.com/aPciDKR8

The enhancer version of the enhanced classes is 2, but the enhancer is
1674154, which matches the SVN revision of the enhancer, and I believe
that's what it should be. I don't know where it gets the 2 from.




Re: Test failures for 2.4.2

2018-04-06 Thread Matthew Broadhead

Hi Pawel,
This list can be a bit slow but I am a member here and this project is 
active.  I looked at your pastebin but couldn't work out your problem.  
you could try on TomEE list.  Romain will probably respond as 2.4.2 is 
the version used by TomEE

Matthew

On 03/04/2018 00:29, Pawel Veselov wrote:

Hello.

I'm trying to build openjpa-2.4.2 myself.
I'm seeing test failures in openjpa-xmlstore : https://pastebin.com/mvns1pDN
Any idea how they can be avoided, or what the cause is?

Thank you,
   Pawel.




multiple persistence units

2018-03-16 Thread Matthew Broadhead

hi,
OpenJPA 2.4.2, TomEE 7.0.3
i have another problem with multiple persistence units...
my persistence.xml looks like this:

http://java.sun.com/xml/ns/persistence;
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd;

    version="2.0">
    
        file
        uk.me.kissy.file.entities.jpa.Box
uk.me.kissy.file.entities.jpa.Category
uk.me.kissy.file.entities.jpa.CqsReview
uk.me.kissy.file.entities.jpa.Department
uk.me.kissy.file.entities.jpa.Enclosure
uk.me.kissy.file.entities.jpa.Event
uk.me.kissy.file.entities.jpa.EventData
uk.me.kissy.file.entities.jpa.EventType
        
        uk.me.kissy.file.entities.jpa.Log
uk.me.kissy.file.entities.jpa.Note
uk.me.kissy.file.entities.jpa.Payment
uk.me.kissy.file.entities.jpa.Price
uk.me.kissy.file.entities.jpa.Undertaking
uk.me.kissy.file.entities.jpa.UndertakingType
uk.me.kissy.file.entities.jpa.Workflow
        
            value="buildSchema(ForeignKeys=true)" />

        
    
    
        operator
uk.me.kissy.file.entities.jpa.operator.Address
uk.me.kissy.file.entities.jpa.operator.Client
uk.me.kissy.file.entities.jpa.operator.Council
uk.me.kissy.file.entities.jpa.operator.Operator
uk.me.kissy.file.entities.jpa.operator.Posttown
uk.me.kissy.file.entities.jpa.operator.Wtr_auth
    

but when i start the container the tables from operator are generated 
inside the file database.  is there some way to stop this from happening?


also, is OpenJPA deprecated?  there doesn't seem to be any activity on 
here any more?


Re: multiple persistence units

2018-03-15 Thread Matthew Broadhead

actually don't worry it seems to be working now.

i was disposing the entitymanager like this:
public void dispose(@Disposes @Any EntityManager entityManager) {
       if (entityManager.isOpen()) {
            entityManager.close();
        }
    }

whereas i needed to do this
public void disposeFile(@Disposes @Default @File EntityManager 
entityManager) {

        if (entityManager.isOpen()) {
            entityManager.close();
        }
    }

    public void disposeOperator(@Disposes @Operator EntityManager 
entityManager) {

        if (entityManager.isOpen()) {
            entityManager.close();
        }
    }

On 14/03/2018 20:13, Matthew Broadhead wrote:

Hi,
OpenJPA 2.4.2, TomEE 7.0.3
since changing to multiple persistence units in the persistence.xml i 
now get this message when trying to merge an @Entity
 
org.apache.openjpa.persistence.InvalidStateException: Encountered 
unmanaged object "uk.me.kissy.file.entities.jpa.Category-3" in life 
cycle state  unmanaged while cascading persistence via field 
"uk.me.kissy.file.entities.jpa.File.category" during flush. However, 
this field does not allow cascade persist. You cannot flush unmanaged 
objects or graphs that have persistent associations to unmanaged objects.
 Suggested actions: a) Set the cascade attribute for this field to 
CascadeType.PERSIST or CascadeType.ALL (JPA annotations) or "persist" 
or "all" (JPA orm.xml),

 b) enable cascade-persist globally,
 c) manually persist the related field value prior to flushing.
 d) if the reference belongs to another context, allow reference to it 
by setting StoreContext.setAllowReferenceToSiblingContext().

FailedObject: uk.me.kissy.file.entities.jpa.Category-3
    at 
org.apache.openjpa.kernel.SingleFieldManager.preFlushPC(SingleFieldManager.java:786)
    at 
org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:621)
    at 
org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:589)
    at 
org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:510)
    at 
org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:3055)
    at 
org.apache.openjpa.kernel.PDirtyState.beforeFlush(PDirtyState.java:39)
    at 
org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:1072)
it seems like it is trying to persist an entity which should already 
exist and be connected?




multiple persistence units

2018-03-14 Thread Matthew Broadhead

Hi,
OpenJPA 2.4.2, TomEE 7.0.3
since changing to multiple persistence units in the persistence.xml i 
now get this message when trying to merge an @Entity
 
org.apache.openjpa.persistence.InvalidStateException: Encountered 
unmanaged object "uk.me.kissy.file.entities.jpa.Category-3" in life 
cycle state  unmanaged while cascading persistence via field 
"uk.me.kissy.file.entities.jpa.File.category" during flush. However, 
this field does not allow cascade persist. You cannot flush unmanaged 
objects or graphs that have persistent associations to unmanaged objects.
 Suggested actions: a) Set the cascade attribute for this field to 
CascadeType.PERSIST or CascadeType.ALL (JPA annotations) or "persist" or 
"all" (JPA orm.xml),

 b) enable cascade-persist globally,
 c) manually persist the related field value prior to flushing.
 d) if the reference belongs to another context, allow reference to it 
by setting StoreContext.setAllowReferenceToSiblingContext().

FailedObject: uk.me.kissy.file.entities.jpa.Category-3
    at 
org.apache.openjpa.kernel.SingleFieldManager.preFlushPC(SingleFieldManager.java:786)
    at 
org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:621)
    at 
org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:589)
    at 
org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:510)
    at 
org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:3055)
    at 
org.apache.openjpa.kernel.PDirtyState.beforeFlush(PDirtyState.java:39)
    at 
org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:1072)
it seems like it is trying to persist an entity which should already 
exist and be connected?


Re: named-native-query with sql-result-set-mapping

2018-03-08 Thread Matthew Broadhead

BTW i am using OpenJPA 2.4.2 (JPA 2.0)

strange but if i completely remove the result-set-mapping and simply use 
the resultClass parameter it works fine
TypedQuery q = 
em.createNamedQuery("selectCategoryYear", CategoryYearResult.class);

List categoryYearResultList = q.getResultList();

i did use your suggestion of figuring out what types were being returned 
inside Object[] to tune the resultClass types


On 08/03/2018 13:46, Craig Taylor wrote:

Try using longs instead of integer.  If you grab the result set without
conversion you should be able to iterate through the list to see what is
being returned.

On Mar 8, 2018 07:38, "Matthew Broadhead" <matthew.broadh...@nbmlaw.co.uk>
wrote:


hi i am trying to do a NamedNativeQuery with a SqlResultSetMapping and i
get javax.el.ELException: java.lang.ClassCastException: [Ljava.lang.Object;
cannot be cast to uk.me.kissy.file.entities.categoryYear.CategoryYearResult.
is this type of operation not supported?
my orm.xml is

http://xmlns.jcp.org/xml/ns/persistence/orm; xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance;
 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm
http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd;>
 
 
 
 
 
 
 
 
 
 
 
 






Re: named-native-query with sql-result-set-mapping

2018-03-08 Thread Matthew Broadhead

Query q = em.createNamedQuery("selectCategoryYear");
        List objectList = q.getResultList();
        for (Object o : objectList) {
            System.out.println(o.getClass().getSimpleName());
        }
it says it is returning Object[]

On 08/03/2018 13:46, Craig Taylor wrote:

Try using longs instead of integer.  If you grab the result set without
conversion you should be able to iterate through the list to see what is
being returned.

On Mar 8, 2018 07:38, "Matthew Broadhead" <matthew.broadh...@nbmlaw.co.uk>
wrote:


hi i am trying to do a NamedNativeQuery with a SqlResultSetMapping and i
get javax.el.ELException: java.lang.ClassCastException: [Ljava.lang.Object;
cannot be cast to uk.me.kissy.file.entities.categoryYear.CategoryYearResult.
is this type of operation not supported?
my orm.xml is

http://xmlns.jcp.org/xml/ns/persistence/orm; xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance;
 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm
http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd;>
 
 
 
 
 
 
 
 
 
 
 
 






named-native-query with sql-result-set-mapping

2018-03-08 Thread Matthew Broadhead
hi i am trying to do a NamedNativeQuery with a SqlResultSetMapping and i 
get javax.el.ELException: java.lang.ClassCastException: 
[Ljava.lang.Object; cannot be cast to 
uk.me.kissy.file.entities.categoryYear.CategoryYearResult.  is this type 
of operation not supported?

my orm.xml is

    xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm 
http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd;>

    
        
            

        
        
            
                
                
                
            
        
    



criteriabuilder mysql date_sub function

2018-01-14 Thread Matthew Broadhead

TomEE 7.0.3 (OpenJPA 2.4.2)
I am trying to write the following statement using CriteriaBuilder:
select t0.* from my_table as t0 where date(now()) between 
date_sub(t0.customdate, INTERVAL t0.reminder DAY) and t0.customdate

I thought it might look something like this:
CriteriaBuilder cb = em.getCriteriaBuilder();
cb.between(new Date(), cb.function("date_sub", Date.class, 
myTable.get(MyTable_.customdate), myTable.get(MyTable_.customdate)), 
myTable.get(MyTable_.customdate))

But I can't work out how to finish it


@Converter @Strategy @Externalizer @Factory multiple fail?

2017-09-14 Thread Matthew Broadhead
i am using TomEE 7.0.3 which ships with OpenJPA 2.4.2.  the database is 
MySQL


i want to store a String (MySQL text column) in the database but use 
JAXB to marshal and unmarshal the POJOs.  the main class is annotated 
with @XmlRootElement. it is also serializable, as are the children objects.


i tried to use javax.persistence.Converter specifically 
javax.persistence.AttributeConverter but it just gives
org.apache.openjpa.persistence.ArgumentException - No registered 
metadata for type "class 
uk.me.kissy.sales.entities.jpa.LeadScriptConverter". This can happen if 
this class has not been annotated as a persistent entity or specified in 
the persistence unit (ex: in the orm.xml).

i had the class listed in the persistence.xml.  maybe 2.4.2 is only JPA 2.0?

then i found this article 
https://rmannibucau.wordpress.com/2015/06/18/openjpa-and-serialization-or-how-to-replace-attributeconverterof-jpa-2-1-in-jpa-2-0/ 
and tried Romain's suggestion using @Externalizer and @Factory 
(org.apache.openjpa.persistence.Externalizer and 
org.apache.openjpa.persistence.Factory).  This results in
Caused by: java.io.StreamCorruptedException: invalid stream header: 
3C71756F.  with and without @Persistent annotating the field


at the bottom of the article i found Struberg's suggestion 
https://github.com/rsandtner/openjpa-converter/blob/master/src/main/java/com/github/rsandtner/openjpaconverter/JodaTimeValueHandler.java 
and 
https://github.com/rsandtner/openjpa-converter/blob/master/src/test/resources/META-INF/persistence.xml#L61. 
this loads the POJO correctly but fails to commit the object back to the 
database during em.merge and em.persist.  there is a gist here 
https://gist.github.com/chongma/5510953224939ef9871ff6197de992e6


FYI i am using the deltaspike 1.8.0 @Transactional 
org.apache.deltaspike.jpa.api.transaction.Transactional to wrap the 
transactions in case that might be interfering.





CriteriaDelete / CriteriaUpdate

2017-09-12 Thread Matthew Broadhead
is this not implemented in 2.4.2?  in TomEE 7.0.3 i get 
java.lang.AbstractMethodError


Re: native query

2017-09-09 Thread Matthew Broadhead
i just moved to openjpa from eclipselink.  i didn't ever use hibernate. 
so i am not sure what the sample code would look like.  i thought they 
were all wrapped with the javax.persistence.* package now?


On 08/09/2017 10:09, Mark Struberg wrote:

puh, cannot answer out of my head, but will write a unit test to dig.
Might help if you could provide a sample which also runs against EclipseLink 
and Hibernate.
After all this is also about interoperability.

LieGrue,
strub


Am 07.09.2017 um 18:56 schrieb Matthew Broadhead 
<matthew.broadh...@nbmlaw.co.uk>:

hi i tried this but it seems to just hang.  is this not supported?

private void updateAutoIncrement(int currentId) {
   Query q = em.createNativeQuery("ALTER TABLE test auto_increment = ?;");
   q.setParameter(1, (currentId + 2));
   q.executeUpdate();
}




native query

2017-09-07 Thread Matthew Broadhead

hi i tried this but it seems to just hang.  is this not supported?

private void updateAutoIncrement(int currentId) {
  Query q = em.createNativeQuery("ALTER TABLE test auto_increment = ?;");
  q.setParameter(1, (currentId + 2));
  q.executeUpdate();
}


populating objects between webapps

2017-08-25 Thread Matthew Broadhead

if i have two webapps:
- directory
- file
they both access databases with the same names:
- directory
- file
in the directory database there is a table called user with the 
following fields:

- id
- firstname
- secondname
in the file database there is a table called file with the following fields:
- id
- something
- userid
if i build a File @Entity which has a transient User object what is the 
best way to populate those objects during the queries?


currently i am aiming to make a rest interface on directory and passing 
all the userids from the File objects and returning the User objects.  
is the recommended way to do this?


Also, JAX-WS seems much better for passing objects between webapps as it 
constructs the objects in the second project.  i have been using JAX-RS 
and it seems i have to keep all the objects in a common jar file for use 
in both projects.  is there a recommended method for passing objects 
between the webapps? (i may be getting off topic here but any experience 
you may have would be much appreciated)





filter sub collection

2017-07-21 Thread Matthew Broadhead
consider that i have an entity "EntityZ" which has a sub collection list 
of "Detail" entities.  the "Detail" entity has a Date field called 
"archived".


how would i return an "EntityZ" entity with only the "Detail" entities 
where "archived" is null?


i have considered 2 options:
- build a whole new set of objects to populate (seems stupid and wasteful)
- try to not render the objects in front end (in JSF the only way to do 
this seems to be to hide the h:dataTable row using css)


JPA criteria

2017-07-21 Thread Matthew Broadhead
Following the example on page 
https://openjpa.apache.org/builds/2.4.2/apache-openjpa/docs/jpa_overview_criteria.html


CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery criteriaQuery = 
criteriaBuilder.createQuery(EntityZ.class);

Root entity = criteriaQuery.from(EntityZ.class);
Root detail = entity.join(entity.get(EntityZ_.details));

results in

Type mismatch: cannot convert from Expression to 
SingularAttribute


also is there a typo?

qdef.where(customer.get(Customer_.name).equal("John 
Doe").and(order.get(Order_.status).equal(OrderStatus.DELIVERED).not()));


there is no such function as equal?  should it be equals?  also in my case:

criteriaQuery.where(entity.get(EntityZ_.id).equals(entityId));

results in:

The method where(Expression) in the type CriteriaQuery 
is not applicable for the arguments (boolean)


Re: generating metamodel

2017-07-21 Thread Matthew Broadhead
i fixed it with 
https://rmannibucau.wordpress.com/2013/01/24/enhancing-openjpa-classes-with-maven-maven-compiler-alternative/



org.bsc.maven
maven-processor-plugin
2.1.0


process

process

generate-sources

-Aopenjpa.source=8 
-Aopenjpa.metamodel=true


org.apache.openjpa.persistence.meta.AnnotationProcessor8

target/generated-sources/metamodel






org.codehaus.mojo
build-helper-maven-plugin
1.7


add-source
generate-sources

add-source



target/generated-sources/metamodel






but if anyone knows a better way please let  me know

On 21/07/2017 09:18, Matthew Broadhead wrote:

i want to try CriteriaBuilder for constructing queries.

i am sure i used to generate the canonical metamodel classes 
automatically by adding a parameter to the persistence.xml but i 
cannot find anything on the mailing list or in the docs.  i have found 
instructions for generating the classes on the command line 
https://openjpa.apache.org/builds/2.4.2/apache-openjpa/docs/ch13s04.html 
and some mentions of using maven on the mailing list.  it seems a long 
winded way of generating the model.


does anyone know how to get them generating automatically in the project?




Re: fetching associations

2016-11-15 Thread Matthew Broadhead
it seems like quite a complicated example for my needs.  I really just 
wanted a simple way to view database data in JSF.


but i will try to push on...

BaseEntity implements two functions
public abstract Long getId();
public abstract Integer getOptlock();

my entities have id names like widget1Id, widget2Id, widget3Id. also i 
have no such field as optlock.  so how do i make a generic baseentity in 
this case? do i need to include this in my database structure?


On 14/11/2016 23:03, Mark Struberg wrote:

Hi Matthew!

EclipseLink seems to open a new connection for lazy loading by using a new 
temporary EntityManager and Transaction. And no XA transaction afaik.
Of course this is by far not a portable behaviour as neither Hibernate nor 
OpenJPA support this. I also have no clue how it behaves in case of an 
OptimisticLockException. I mean the lazy loading can literally happen a few 
minutes later...

Whether to go back to EclipseLink is a question on how your whole application 
looks like. You did use a non-portable feature and of course it is now a bit 
harder to switch providers. But it's not impossible.
The usual solution is to keep the EntityManager open for the whole request.
How big is your app and how old is the codebase?
Do you use XA or resource-local?
Does it use many EJBs or do you already mainly use CDI?

In case of the later you can use a @RequestScoped EntityManager + DeltaSpike 
@Transactional for example.
https://deltaspike.apache.org/documentation/jpa.html

Sample code
With XA (JTA):
https://github.com/struberg/lightweightEE/blob/jtacdi11/backend/src/main/java/de/jaxenter/eesummit/caroline/backend/tools/EntityManagerProducer.java#L35
https://github.com/struberg/lightweightEE/blob/jtacdi11/backend/src/main/java/de/jaxenter/eesummit/caroline/backend/impl/EmployeeServiceImpl.java
https://github.com/struberg/lightweightEE/blob/jtacdi11/backend-api/src/main/resources/META-INF/persistence.xml#L9
https://github.com/struberg/lightweightEE/blob/jtacdi11/gui/src/main/tomee/conf/tomee.xml

With ResourceLocal:
https://github.com/struberg/lightweightEE/blob/cdi11/backend/src/main/java/de/jaxenter/eesummit/caroline/backend/tools/EntityManagerProducer.java
https://github.com/struberg/lightweightEE/blob/cdi11/backend/src/main/java/de/jaxenter/eesummit/caroline/backend/impl/EmployeeServiceImpl.java
https://github.com/struberg/lightweightEE/blob/cdi11/backend/src/main/resources/persistence-CaroLine.properties
https://github.com/struberg/lightweightEE/blob/cdi11/backend-api/src/main/resources/META-INF/persistence.xml


I also wrote a few blog posts which might help you understand this topic, e.g.
https://struberg.wordpress.com/2015/04/21/transaction-and-exception-handling-in-ejbs-and-javaee7-transactional/

Of course the entitymanager-per-request pattern also has a few limitations, 
e.g. if cannot lazy load data in subsequent responses (data has to be rendered 
during the initial request).
But it's rather easy to prevent such a scenario. Usually you will only use 
Entities in CRUD dialogues anyway.
I would e.g. _not_ use the entities in DataTables on a search dialogue. In that 
case I'd rather use a dedicated list item via SELECT NEW. This is much faster, 
has way less memory overhead and also will prevent you from a lot optimistic 
locking pain.

Feel free to ask more questions, this is a rather complex and often not well 
enough understood topic.

LieGrue,
strub





Am 14.11.2016 um 20:12 schrieb Matthew Broadhead 
<matthew.broadh...@nbmlaw.co.uk>:

so if the managedbean is not an ejb anymore and therefore the transaction is closed how 
does it work for eclipselink?  do they use some magic?  are there any plans for 
implementing this "feature" in the future?  after spending a few months 
migrating to myfaces and openjpa on the suggestion of romain i now find that openjpa 
cannot lazy load entities from jsf which is fairly disappointing to say the least.  is my 
best route to go back to eclipselink?

On 09/11/2016 17:40, Mark Struberg wrote:

Oki all clear. The internal EntityManager will get closed when you leave the 
outer @Stateless method.
@Stateless EJBSs really are nothing else than beans with an interceptor which 
opens and commits the transaction and EntityManager on the outermost EJB level.

Since the @ManagedBean is not an EJB anymore you don't have any transaction nor 
EntityManager open anymore in your render_response phase in JSF. Which means 
that OpenJPA cannot provide lazyloading for you.

I personally prefer to use the entitymanager-per-request patter and using CDI 
with a @RequestScoped EntityManager. But that might be a bigger change in 
architecture for you.
Other options are:

* touching the required bits in your DAO

* using eager fetching
* using a fetch-plan
* using DTOs

LieGrue,
strub






On Wednesday, 9 November 2016, 17:31, Matthew Broadhead 
<matthew.broadh...@nbmlaw.co.uk> wrote:

sorry for the delay in replying i was very busy

as a simple example 

Re: fetching associations

2016-11-15 Thread Matthew Broadhead

sorry just found it.  my bad

On 15/11/2016 14:07, Matthew Broadhead wrote:

Hi strub,

i am making a test project using cdi.  i am creating an equivalent of 
the EmployeeServiceImpl.  it implements 
de.jaxenter.eesummit.caroline.backend.api.EmployeeService; which 
doesn't seem to be in the repository.  am i missing something?


Matthew

On 14/11/2016 23:03, Mark Struberg wrote:

Hi Matthew!

EclipseLink seems to open a new connection for lazy loading by using 
a new temporary EntityManager and Transaction. And no XA transaction 
afaik.
Of course this is by far not a portable behaviour as neither 
Hibernate nor OpenJPA support this. I also have no clue how it 
behaves in case of an OptimisticLockException. I mean the lazy 
loading can literally happen a few minutes later...


Whether to go back to EclipseLink is a question on how your whole 
application looks like. You did use a non-portable feature and of 
course it is now a bit harder to switch providers. But it's not 
impossible.
The usual solution is to keep the EntityManager open for the whole 
request.

How big is your app and how old is the codebase?
Do you use XA or resource-local?
Does it use many EJBs or do you already mainly use CDI?

In case of the later you can use a @RequestScoped EntityManager + 
DeltaSpike @Transactional for example.

https://deltaspike.apache.org/documentation/jpa.html

Sample code
With XA (JTA):
https://github.com/struberg/lightweightEE/blob/jtacdi11/backend/src/main/java/de/jaxenter/eesummit/caroline/backend/tools/EntityManagerProducer.java#L35 

https://github.com/struberg/lightweightEE/blob/jtacdi11/backend/src/main/java/de/jaxenter/eesummit/caroline/backend/impl/EmployeeServiceImpl.java 

https://github.com/struberg/lightweightEE/blob/jtacdi11/backend-api/src/main/resources/META-INF/persistence.xml#L9 

https://github.com/struberg/lightweightEE/blob/jtacdi11/gui/src/main/tomee/conf/tomee.xml 



With ResourceLocal:
https://github.com/struberg/lightweightEE/blob/cdi11/backend/src/main/java/de/jaxenter/eesummit/caroline/backend/tools/EntityManagerProducer.java 

https://github.com/struberg/lightweightEE/blob/cdi11/backend/src/main/java/de/jaxenter/eesummit/caroline/backend/impl/EmployeeServiceImpl.java 

https://github.com/struberg/lightweightEE/blob/cdi11/backend/src/main/resources/persistence-CaroLine.properties 

https://github.com/struberg/lightweightEE/blob/cdi11/backend-api/src/main/resources/META-INF/persistence.xml 




I also wrote a few blog posts which might help you understand this 
topic, e.g.
https://struberg.wordpress.com/2015/04/21/transaction-and-exception-handling-in-ejbs-and-javaee7-transactional/ 



Of course the entitymanager-per-request pattern also has a few 
limitations, e.g. if cannot lazy load data in subsequent responses 
(data has to be rendered during the initial request).
But it's rather easy to prevent such a scenario. Usually you will 
only use Entities in CRUD dialogues anyway.
I would e.g. _not_ use the entities in DataTables on a search 
dialogue. In that case I'd rather use a dedicated list item via 
SELECT NEW. This is much faster, has way less memory overhead and 
also will prevent you from a lot optimistic locking pain.


Feel free to ask more questions, this is a rather complex and often 
not well enough understood topic.


LieGrue,
strub




Am 14.11.2016 um 20:12 schrieb Matthew Broadhead 
<matthew.broadh...@nbmlaw.co.uk>:


so if the managedbean is not an ejb anymore and therefore the 
transaction is closed how does it work for eclipselink?  do they use 
some magic?  are there any plans for implementing this "feature" in 
the future?  after spending a few months migrating to myfaces and 
openjpa on the suggestion of romain i now find that openjpa cannot 
lazy load entities from jsf which is fairly disappointing to say the 
least.  is my best route to go back to eclipselink?


On 09/11/2016 17:40, Mark Struberg wrote:
Oki all clear. The internal EntityManager will get closed when you 
leave the outer @Stateless method.
@Stateless EJBSs really are nothing else than beans with an 
interceptor which opens and commits the transaction and 
EntityManager on the outermost EJB level.


Since the @ManagedBean is not an EJB anymore you don't have any 
transaction nor EntityManager open anymore in your render_response 
phase in JSF. Which means that OpenJPA cannot provide lazyloading 
for you.


I personally prefer to use the entitymanager-per-request patter and 
using CDI with a @RequestScoped EntityManager. But that might be a 
bigger change in architecture for you.

Other options are:

* touching the required bits in your DAO

* using eager fetching
* using a fetch-plan
* using DTOs

LieGrue,
strub





On Wednesday, 9 November 2016, 17:31, Matthew Broadhead 
<matthew.broadh...@nbmlaw.co.uk> wrote:

sorry for the delay in replying i was very busy
as a simple example there is a generic Dao class to return the 
results

of a namedquery
@Stat

Re: fetching associations

2016-11-15 Thread Matthew Broadhead

Hi strub,

i am making a test project using cdi.  i am creating an equivalent of 
the EmployeeServiceImpl.  it implements 
de.jaxenter.eesummit.caroline.backend.api.EmployeeService; which doesn't 
seem to be in the repository.  am i missing something?


Matthew

On 14/11/2016 23:03, Mark Struberg wrote:

Hi Matthew!

EclipseLink seems to open a new connection for lazy loading by using a new 
temporary EntityManager and Transaction. And no XA transaction afaik.
Of course this is by far not a portable behaviour as neither Hibernate nor 
OpenJPA support this. I also have no clue how it behaves in case of an 
OptimisticLockException. I mean the lazy loading can literally happen a few 
minutes later...

Whether to go back to EclipseLink is a question on how your whole application 
looks like. You did use a non-portable feature and of course it is now a bit 
harder to switch providers. But it's not impossible.
The usual solution is to keep the EntityManager open for the whole request.
How big is your app and how old is the codebase?
Do you use XA or resource-local?
Does it use many EJBs or do you already mainly use CDI?

In case of the later you can use a @RequestScoped EntityManager + DeltaSpike 
@Transactional for example.
https://deltaspike.apache.org/documentation/jpa.html

Sample code
With XA (JTA):
https://github.com/struberg/lightweightEE/blob/jtacdi11/backend/src/main/java/de/jaxenter/eesummit/caroline/backend/tools/EntityManagerProducer.java#L35
https://github.com/struberg/lightweightEE/blob/jtacdi11/backend/src/main/java/de/jaxenter/eesummit/caroline/backend/impl/EmployeeServiceImpl.java
https://github.com/struberg/lightweightEE/blob/jtacdi11/backend-api/src/main/resources/META-INF/persistence.xml#L9
https://github.com/struberg/lightweightEE/blob/jtacdi11/gui/src/main/tomee/conf/tomee.xml

With ResourceLocal:
https://github.com/struberg/lightweightEE/blob/cdi11/backend/src/main/java/de/jaxenter/eesummit/caroline/backend/tools/EntityManagerProducer.java
https://github.com/struberg/lightweightEE/blob/cdi11/backend/src/main/java/de/jaxenter/eesummit/caroline/backend/impl/EmployeeServiceImpl.java
https://github.com/struberg/lightweightEE/blob/cdi11/backend/src/main/resources/persistence-CaroLine.properties
https://github.com/struberg/lightweightEE/blob/cdi11/backend-api/src/main/resources/META-INF/persistence.xml


I also wrote a few blog posts which might help you understand this topic, e.g.
https://struberg.wordpress.com/2015/04/21/transaction-and-exception-handling-in-ejbs-and-javaee7-transactional/

Of course the entitymanager-per-request pattern also has a few limitations, 
e.g. if cannot lazy load data in subsequent responses (data has to be rendered 
during the initial request).
But it's rather easy to prevent such a scenario. Usually you will only use 
Entities in CRUD dialogues anyway.
I would e.g. _not_ use the entities in DataTables on a search dialogue. In that 
case I'd rather use a dedicated list item via SELECT NEW. This is much faster, 
has way less memory overhead and also will prevent you from a lot optimistic 
locking pain.

Feel free to ask more questions, this is a rather complex and often not well 
enough understood topic.

LieGrue,
strub





Am 14.11.2016 um 20:12 schrieb Matthew Broadhead 
<matthew.broadh...@nbmlaw.co.uk>:

so if the managedbean is not an ejb anymore and therefore the transaction is closed how 
does it work for eclipselink?  do they use some magic?  are there any plans for 
implementing this "feature" in the future?  after spending a few months 
migrating to myfaces and openjpa on the suggestion of romain i now find that openjpa 
cannot lazy load entities from jsf which is fairly disappointing to say the least.  is my 
best route to go back to eclipselink?

On 09/11/2016 17:40, Mark Struberg wrote:

Oki all clear. The internal EntityManager will get closed when you leave the 
outer @Stateless method.
@Stateless EJBSs really are nothing else than beans with an interceptor which 
opens and commits the transaction and EntityManager on the outermost EJB level.

Since the @ManagedBean is not an EJB anymore you don't have any transaction nor 
EntityManager open anymore in your render_response phase in JSF. Which means 
that OpenJPA cannot provide lazyloading for you.

I personally prefer to use the entitymanager-per-request patter and using CDI 
with a @RequestScoped EntityManager. But that might be a bigger change in 
architecture for you.
Other options are:

* touching the required bits in your DAO

* using eager fetching
* using a fetch-plan
* using DTOs

LieGrue,
strub






On Wednesday, 9 November 2016, 17:31, Matthew Broadhead 
<matthew.broadh...@nbmlaw.co.uk> wrote:

sorry for the delay in replying i was very busy

as a simple example there is a generic Dao class to return the results
of a namedquery
@Stateless
public class DAO {
  @PersistenceContext(unitName = "widgetDataSource")
  private EntityManager em;
  

Re: fetching associations

2016-11-14 Thread Matthew Broadhead
so if the managedbean is not an ejb anymore and therefore the 
transaction is closed how does it work for eclipselink?  do they use 
some magic?  are there any plans for implementing this "feature" in the 
future?  after spending a few months migrating to myfaces and openjpa on 
the suggestion of romain i now find that openjpa cannot lazy load 
entities from jsf which is fairly disappointing to say the least.  is my 
best route to go back to eclipselink?


On 09/11/2016 17:40, Mark Struberg wrote:

Oki all clear. The internal EntityManager will get closed when you leave the 
outer @Stateless method.
@Stateless EJBSs really are nothing else than beans with an interceptor which 
opens and commits the transaction and EntityManager on the outermost EJB level.

Since the @ManagedBean is not an EJB anymore you don't have any transaction nor 
EntityManager open anymore in your render_response phase in JSF. Which means 
that OpenJPA cannot provide lazyloading for you.

I personally prefer to use the entitymanager-per-request patter and using CDI 
with a @RequestScoped EntityManager. But that might be a bigger change in 
architecture for you.
Other options are:

* touching the required bits in your DAO

* using eager fetching
* using a fetch-plan
* using DTOs

LieGrue,
strub






On Wednesday, 9 November 2016, 17:31, Matthew Broadhead 
<matthew.broadh...@nbmlaw.co.uk> wrote:

sorry for the delay in replying i was very busy

as a simple example there is a generic Dao class to return the results
of a namedquery
@Stateless
public class DAO {
  @PersistenceContext(unitName = "widgetDataSource")
  private EntityManager em;
  
  @SuppressWarnings("unchecked")
  public  List namedFind(Class clazz, String
query) {
  return em.createNamedQuery(query, clazz).getResultList();
  }
  
}
call the namedFind from another stateless
@Stateless
public class WidgetDAO {
  @EJB
  private DAO dao;
  ...
  public List findAll() {
  return dao.namedFind(Widget.class, "Widget.findAll");
  }
  
}
this is loaded into a managedbean
@ManagedBean
@ViewScoped
public class WidgetBean {
  @EJB
  private WidgetDAO widgetDao;
  private List widgetList;
  public void onload(){
  setWigdetList(widgetDao.fildAll());
  }
  ...setter getter of widgetList
}
which is supposed to display in jsf

http://www.w3.org/1999/xhtml;
  xmlns:h="http://java.sun.com/jsf/html;
  xmlns:ui="http://java.sun.com/jsf/facelets;
  xmlns:f="http://java.sun.com/jsf/core;
  template="/WEB-INF/include/layout.xhtml">
  ...
  
  
  ...where are the sub widgets?
  
  


Like i say if i loop through the widgets (or maybe the subwidgets as
well) it then loads in the JSF.  so it lazy loads in java but not in
JSF.  should i change to eager when i generate the entities or is there
something else i can do?  is it supposed to work the same as eclipselink?


On 02/11/2016 08:06, Mark Struberg wrote:

  Hi Matthew!

  Now I'm back on my notebook.
  What transaction mechanism are you using? JTA or ResourceLocal?
  And what technology to control the transactions? EJBs? CDI? Spring?

  It boils down to be more a question about appliction architecture than

about OpenJPA, but still very important to cover. So just go ahead, I'm
pretty sure we can help you.

  LieGrue,
  strub


  Am 24.10.2016 um 10:34 schrieb Matthew Broadhead

<matthew.broadh...@nbmlaw.co.uk>:

  HI, I am using TomEE 7.0.1 and I just switched from Plume to Plus. I

was using eclipselink and now I am converting to OpenJPA.  When I fetch a set of
entities and then try to iterate through their associations in JSF the list is
empty.  in eclipselink they were populated by default.  if i loop through the
entities in Java before displaying in JSF then they are populated (i guess they
get lazy loaded).  is there a setting that needs to be changed?  like generating
with all associations as eager or setting a flag in persistence.xml?  what would
give the same default as eclipselink? seemed like an easy question but i could
not find anything by searching.



Re: fetching associations

2016-11-11 Thread Matthew Broadhead
can you point me to any examples of a strategy i can use which will give 
it the same behaviour as eclipselink?  ideally i want to grab the 
objects and view them in jsf without any messing around


On 09/11/2016 17:40, Mark Struberg wrote:

Oki all clear. The internal EntityManager will get closed when you leave the 
outer @Stateless method.
@Stateless EJBSs really are nothing else than beans with an interceptor which 
opens and commits the transaction and EntityManager on the outermost EJB level.

Since the @ManagedBean is not an EJB anymore you don't have any transaction nor 
EntityManager open anymore in your render_response phase in JSF. Which means 
that OpenJPA cannot provide lazyloading for you.

I personally prefer to use the entitymanager-per-request patter and using CDI 
with a @RequestScoped EntityManager. But that might be a bigger change in 
architecture for you.
Other options are:

* touching the required bits in your DAO

* using eager fetching
* using a fetch-plan
* using DTOs

LieGrue,
strub






On Wednesday, 9 November 2016, 17:31, Matthew Broadhead 
<matthew.broadh...@nbmlaw.co.uk> wrote:

sorry for the delay in replying i was very busy

as a simple example there is a generic Dao class to return the results
of a namedquery
@Stateless
public class DAO {
  @PersistenceContext(unitName = "widgetDataSource")
  private EntityManager em;
  
  @SuppressWarnings("unchecked")
  public  List namedFind(Class clazz, String
query) {
  return em.createNamedQuery(query, clazz).getResultList();
  }
  
}
call the namedFind from another stateless
@Stateless
public class WidgetDAO {
  @EJB
  private DAO dao;
  ...
  public List findAll() {
  return dao.namedFind(Widget.class, "Widget.findAll");
  }
  
}
this is loaded into a managedbean
@ManagedBean
@ViewScoped
public class WidgetBean {
  @EJB
  private WidgetDAO widgetDao;
  private List widgetList;
  public void onload(){
  setWigdetList(widgetDao.fildAll());
  }
  ...setter getter of widgetList
}
which is supposed to display in jsf

http://www.w3.org/1999/xhtml;
  xmlns:h="http://java.sun.com/jsf/html;
  xmlns:ui="http://java.sun.com/jsf/facelets;
  xmlns:f="http://java.sun.com/jsf/core;
  template="/WEB-INF/include/layout.xhtml">
  ...
  
  
  ...where are the sub widgets?
  
  


Like i say if i loop through the widgets (or maybe the subwidgets as
well) it then loads in the JSF.  so it lazy loads in java but not in
JSF.  should i change to eager when i generate the entities or is there
something else i can do?  is it supposed to work the same as eclipselink?


On 02/11/2016 08:06, Mark Struberg wrote:

  Hi Matthew!

  Now I'm back on my notebook.
  What transaction mechanism are you using? JTA or ResourceLocal?
  And what technology to control the transactions? EJBs? CDI? Spring?

  It boils down to be more a question about appliction architecture than

about OpenJPA, but still very important to cover. So just go ahead, I'm
pretty sure we can help you.

  LieGrue,
  strub


  Am 24.10.2016 um 10:34 schrieb Matthew Broadhead

<matthew.broadh...@nbmlaw.co.uk>:

  HI, I am using TomEE 7.0.1 and I just switched from Plume to Plus. I

was using eclipselink and now I am converting to OpenJPA.  When I fetch a set of
entities and then try to iterate through their associations in JSF the list is
empty.  in eclipselink they were populated by default.  if i loop through the
entities in Java before displaying in JSF then they are populated (i guess they
get lazy loaded).  is there a setting that needs to be changed?  like generating
with all associations as eager or setting a flag in persistence.xml?  what would
give the same default as eclipselink? seemed like an easy question but i could
not find anything by searching.



Re: fetching associations

2016-11-09 Thread Matthew Broadhead

sorry for the delay in replying i was very busy

as a simple example there is a generic Dao class to return the results 
of a namedquery

@Stateless
public class DAO {
@PersistenceContext(unitName = "widgetDataSource")
private EntityManager em;

@SuppressWarnings("unchecked")
public  List namedFind(Class clazz, String query) {
return em.createNamedQuery(query, clazz).getResultList();
}

}
call the namedFind from another stateless
@Stateless
public class WidgetDAO {
@EJB
private DAO dao;
...
public List findAll() {
return dao.namedFind(Widget.class, "Widget.findAll");
}

}
this is loaded into a managedbean
@ManagedBean
@ViewScoped
public class WidgetBean {
@EJB
private WidgetDAO widgetDao;
private List widgetList;
public void onload(){
setWigdetList(widgetDao.fildAll());
}
...setter getter of widgetList
}
which is supposed to display in jsf

http://www.w3.org/1999/xhtml;
xmlns:h="http://java.sun.com/jsf/html;
xmlns:ui="http://java.sun.com/jsf/facelets;
xmlns:f="http://java.sun.com/jsf/core;
template="/WEB-INF/include/layout.xhtml">
...


...where are the sub widgets?




Like i say if i loop through the widgets (or maybe the subwidgets as 
well) it then loads in the JSF.  so it lazy loads in java but not in 
JSF.  should i change to eager when i generate the entities or is there 
something else i can do?  is it supposed to work the same as eclipselink?


On 02/11/2016 08:06, Mark Struberg wrote:

Hi Matthew!

Now I'm back on my notebook.
What transaction mechanism are you using? JTA or ResourceLocal?
And what technology to control the transactions? EJBs? CDI? Spring?

It boils down to be more a question about appliction architecture than about 
OpenJPA, but still very important to cover. So just go ahead, I'm pretty sure 
we can help you.

LieGrue,
strub


Am 24.10.2016 um 10:34 schrieb Matthew Broadhead 
<matthew.broadh...@nbmlaw.co.uk>:

HI, I am using TomEE 7.0.1 and I just switched from Plume to Plus. I was using 
eclipselink and now I am converting to OpenJPA.  When I fetch a set of entities 
and then try to iterate through their associations in JSF the list is empty.  
in eclipselink they were populated by default.  if i loop through the entities 
in Java before displaying in JSF then they are populated (i guess they get lazy 
loaded).  is there a setting that needs to be changed?  like generating with 
all associations as eager or setting a flag in persistence.xml?  what would 
give the same default as eclipselink? seemed like an easy question but i could 
not find anything by searching.


fetching associations

2016-10-24 Thread Matthew Broadhead
HI, I am using TomEE 7.0.1 and I just switched from Plume to Plus. I was 
using eclipselink and now I am converting to OpenJPA.  When I fetch a 
set of entities and then try to iterate through their associations in 
JSF the list is empty.  in eclipselink they were populated by default.  
if i loop through the entities in Java before displaying in JSF then 
they are populated (i guess they get lazy loaded).  is there a setting 
that needs to be changed?  like generating with all associations as 
eager or setting a flag in persistence.xml?  what would give the same 
default as eclipselink? seemed like an easy question but i could not 
find anything by searching.


Re: MySQL text field becomes Object

2016-05-02 Thread Matthew Broadhead
forget this question.  i generated using maven plugin and 
ReverseMappingTool and it worked fine


On 02/05/2016 15:59, Matthew Broadhead wrote:

Hi,

I searched the list but couldn't find the answer to this problem.

Using Eclipse IDE when I "Generate Entities from Tables" MySQL text 
fields becomes Objects.  Does OpenJPA not work well with MySQL text 
fields?  Should I be using something else instead?  Or is there 
perhaps a setting I can put somewhere to deal with this problem?


Thanks, Matthew




MySQL text field becomes Object

2016-05-02 Thread Matthew Broadhead

Hi,

I searched the list but couldn't find the answer to this problem.

Using Eclipse IDE when I "Generate Entities from Tables" MySQL text 
fields becomes Objects.  Does OpenJPA not work well with MySQL text 
fields?  Should I be using something else instead?  Or is there perhaps 
a setting I can put somewhere to deal with this problem?


Thanks, Matthew