Leonardo Carvalho | 17 May 18:20 2016
Picon

Const.class conflict


  Hi guys.

  I'm creating a StartsWith and IgnoreCase JPARepository method using SpringData and OpenJPA.
  I've got a strange issue.

  The query is perfect:



  But at runtime, it fails with the message:

  "The filter listener "matches" requires a constant argument. "

  And that looks like is caused by using com.sun.xml.internal.bind.v2.runtime.reflect.opt.Const instead of org.apache.openjpa.jdbc.kernel.exps.Const on the test operation at org.apache.openjpa.jdbc.kernel.exps.JDBCExpressionFactory line 175.



   I'm using Maven 3 and Java 8. Is there a way to solve this apparent conflict?

   Thanks

--


 

Leonardo Trindade de Carvalho

Senior Programmer

SiBBr | MCTI | PNUMA (UNEP)

Phone: +55 61 3329 6031 r6045
Phone: +55 48 8405 4119

trindade-BUiaNDv81daL9npaI8a6UQ@public.gmane.org

www.sibbr.gov.br

 
Senthil Kumar Sekar | 12 May 05:09 2016

Open JPA Entity Loading issue due to failure in Enhancing at run time.


Hello Team,
               We have been using openjpa – 2.4.0 for our application data access layer which will be deployed in Jboss
Fuse 6.2.1.
We have persistence xml where all the entities are declared.

Very Frequently that we are facing the below issue and had to restart the container multiple to get the issue resolved.

java.lang.reflect.UndeclaredThrowableException
        at com.sun.proxy.$Proxy29.createQuery(Unknown Source)
        at com.mysema.query.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:127)[744:com.mysema.querydsl.jpa:3.6.3]
               …………….
Caused by: java.lang.reflect.UndeclaredThrowableException
        at com.sun.proxy.$Proxy103.createQuery(Unknown Source)
        ... 67 more
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.GeneratedMethodAccessor112.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_79]
        at java.lang.reflect.Method.invoke(Method.java:606)[:1.7.0_79]
        at org.apache.aries.jpa.container.impl.EntityManagerProxyFactory$EMHandler.invoke(EntityManagerProxyFactory.java:31)
        ... 68 more
Caused by: <openjpa-2.4.0-r422266:1674604 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: An error occurred while parsing the query
filter "select cETAssignmentException_
from CETAssignmentException cETAssignmentException_
where lower(cETAssignmentException_.id.officeCode) = ?1 and
lower(cETAssignmentException_.id.businessSegmentCode) = ?2". Error message: The name
"CETAssignmentException" is not a recognized entity or identifier. Perhaps you meant
CDDCaseLocation, which is a close match. Known entity names: [IndividualReferencesAsu, RmaExcllist,
WbSanctionsQuestionnaire, IndividualAsu, SpeDocumentsChecklist, Property, MvSciClientGrpInfo,
CddAdditionalDetails, CopiFatcaSubownersInfo, DocumentTemplate, ClientBranchOffices,
RoccoDecisionReportPK, CddCaseActorsPK, DdCase, ClientIndividualReln, EcddSciCasePublish,
ForeignExchange, CaseDetail, CopiFatcaTaxInfo, NorkomTxn, CopiFatcaDocument, ClientGroup,
ClientIndividual, OpaScreen, Country, MvSciClientInfo, IndividualNorkom, CddRisks,
IndividualNorkomAsu, ClientOfficeProducts, CddCaseAuditPK, AtfFieldsMaster,
CddDdrBasedRouting, PreScreening, CddCasePK, MvSciClientOrgInfo, WorkflowState, RoccoRequest,
RoccoRequestAuditPK, Risks, MvSciClientAddrInfo, GaProductTransaction, ClientDocuments, Bba,
ClientBranch, ClientNorkomPK, ClientISIC, MvSciArmCodeInfo, DDCCountries, Client, GroupNorkom,
IndividualClientReln, Ga, OPARuleBases, CDDWorkflowState, SubReasonCodes, MoneyMarket,
OpaError, DefenceGoodsStatus, CDDStateMachine, LegalConstitution, ReasonCodes,
RoccoRequestAudit, Address, BranchNorkom, FiDocumentsChecklist, CopiFatcaStatusInfo, CddCase,
Cdd, CddPepSummary, Bonds, BbaDocumentsChecklist, ClientOffice, CDDCaseLocation, MvSciEmpInfo,
GaDocumentChecklist, TaskBasedReasonCodes, BranchAddress, DgStatusDecisionMatrix,
CashEquities, IndividualReferences, EcddSciPublish, CddCaseAudit, BusinessSubSegment,
OPACases, ClientIndividualRelnPK, IndividualReferencesAsuPK, Product, ClientNorkom,
BusinessSegment, DocumentCategory, CoDocumentsChecklist, CddCaseAuditSubReasons,
IndividualClientRelnAsu, TaskBasedReasonCodesPK, CustomerCountryRisk, PreScreeningComment,
BbaRiskQuestion, IndividualDocuments, FormButton, Documents, BbaAdditionalDetails, ClientType,
GuarantorNorkomPK, AnticipatedTransaction, CddPepDetail, GoodsType, CddCaseActors,
GuarantorNorkom, CddCountryRisk, CountryOffices, CopiFatca, CddWorkflowReassignment, Norkom,
Deferral, DocumentsUpload, ClientTriggerEvents, CopiFatcaStatus, Gic, BusinessSubSegmentPK,
ParentGroupDetails, MvSciClientCoreInfo, RequestMap, CddRiskQuestions, DefenceGoods,
OPADecisionReport, AtfRequestTxn, Individual, ReviewCases, MvSciArmLocation,
DefenceGoodsDecision, ClientIndividualPK, RoccoDecisionReport, IndividualPK, CddTaskAction,
PreScreeningRef, ClientGuarantor, Derivative]
        at org.apache.openjpa.kernel.exps.AbstractExpressionBuilder.parseException(AbstractExpressionBuilder.java:118)[848:org.apache.openjpa:2.4.0]
        at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getClassMetaData(JPQLExpressionBuilder.java:193)[848:org.apache.openjpa:2.4.0]
        at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.resolveClassMetaData(JPQLExpressionBuilder.java:166)[848:org.apache.openjpa:2.4.0]

Looks like the entity CETAssignmentException is not in the open-jpa list which is used in setting the
values using Reflection.

Below is the TRACE log enabled in openjpa.

3724779  bowbMSPersistenceUnit  WARN   [qtp1069331902-407] openjpa.MetaData - The class
"com.scb.cic.wb.cdd.ds.db.model.sci.SciOffices" listed in the openjpa.MetaDataFactory
configuration property could not be loaded by wb-svc-cdd [970]; ignoring.
3724779  bowbMSPersistenceUnit  WARN   [qtp1069331902-407] openjpa.MetaData - The class
"com.scb.cic.wb.cdd.ds.db.model.sci.SciAssignment" listed in the openjpa.MetaDataFactory
configuration property could not be loaded by wb-svc-cdd [970]; ignoring.
3724779  bowbMSPersistenceUnit  WARN   [qtp1069331902-407] openjpa.MetaData - The class
"com.scb.cic.wb.cdd.ds.db.model.task.CETAssignmentExceptionPK" listed in the
openjpa.MetaDataFactory configuration property could not be loaded by wb-svc-cdd [970]; ignoring.
3724779  bowbMSPersistenceUnit  WARN   [qtp1069331902-407] openjpa.MetaData - The class
"com.scb.cic.wb.cdd.ds.db.model.task.CETAssignmentException" listed in the
openjpa.MetaDataFactory configuration property could not be loaded by wb-svc-cdd [970]; ignoring.

and debugged with the source code and found that

private Class<?> classForName(String name, ClassLoader loader) {
        try {
            return Class.forName(name, true, loader);
        } catch (Exception e) {
            if ((_validate & VALIDATE_RUNTIME) != 0) {
                if (_log.isWarnEnabled())
                    _log.warn(_loc.get("bad-discover-class", name, loader));
            } else if (_log.isInfoEnabled())
                _log.info(_loc.get("bad-discover-class", name, loader));
            if (_log.isTraceEnabled())
                _log.trace(e);
        } catch (NoSuchMethodError nsme) {
            if (nsme.getMessage().indexOf(".pc") == -1)
                throw nsme;

            // if the error is about a method that uses the PersistenceCapable
            // 'pc' method prefix, perform some logging and continue. This
            // probably just means that the class is not yet enhanced.
            if ((_validate & VALIDATE_RUNTIME) != 0) {
                if (_log.isWarnEnabled())
                    _log.warn(_loc.get("bad-discover-class", name, loader));
            } else if (_log.isInfoEnabled())
                _log.info(_loc.get("bad-discover-class", name, loader));
            if (_log.isTraceEnabled())
                _log.trace(nsme);
        }
        return null;
    }

Above entities are ignored in enhancement while the class is loaded. So, added below in persistence.xml

<property name="openjpa.RuntimeUnenhancedClasses" value="supported"/> --> in order to enhance
dynamically during run time.

Additionally we have also enabled enhancement during build time by
<plugin>
                    <groupId>org.apache.openjpa</groupId>
                    <artifactId>openjpa-maven-plugin</artifactId>
                    <version>${openjpa-maven-plugin.version}</version>

                    <configuration>
                    </configuration>

                    <executions>
                        <execution>
                            <id>enhancer</id>
                            <phase>process-classes</phase>
                            <goals>
                                <goal>enhance</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

But still facing the same issue.

This issue has become a serious issue. It would be great if the team could help us in resolving the issue.

Thanks.

Regards
Senthil Kumar Sekar

Dan Rollo | 3 May 16:41 2016
Picon
Gravatar

Doc issue

On the following page, the referenced property example to add to ‘persistence.xml’ is not visible in FF, Chrome, nor Safari:

http://openjpa.apache.org/entity-enhancement.html

See the section: OPENJPA-952
The last line of that section does not display the example property. (screenshot attached)

Here’s the page source snippet:
<blockquote>
<p>[java] 1047  jpa_app    WARN   [main] openjpa.Enhance - Unenhanced classes were
detected even though the enhancer has ran. Ensure that the
EntityManagerFactory is created prior to creating any Entities.</p>
</blockquote>
<p>If your application uses some other method of enhancement, this support can be explicitly disabled by setting the following property in your persistence.xml.</p>
<blockquote>
<p><property name="openjpa.DynamicEnhancementAgent" value="false"/></p>
</blockquote>
<p><a name="EntityEnhancement-SubclassingEnhancement"></a></p>


Matthew Broadhead | 2 May 15:59 2016
Picon

MySQL text field becomes Object

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

Sergey Beryozkin | 26 Apr 11:44 2016
Picon

Unexpected 'right truncation' issue

Hi All

This is my first post to the list, I've tried to solve the issue myself 
by checking StackOverflow, etc. I thought I'd give it a try at OpenJPA 
users list, given that I do work with OpenJPA 2.4.0.

I have the following class hierarchy (listing the most relevant details):

 <at> Entity
public class Client {
    private String clientId;
}

 <at> Entity
public class BearerAccessToken extends ServerAccessToken {
}

 <at> MappedSuperclass
public abstract class ServerAccessToken extends AccessToken {

 <at> ManyToOne
private Client client;
}

 <at> MappedSuperclass
public abstract class AccessToken {

 <at> Id
String tokenKey;

 <at> ElementCollection
 <at> MapKeyColumn(name="propName")
private Map<String, String> parameters = new LinkedHashMap<String, 
String>();
}

Now, after initializing the DB as follows:

- Create Client instance (ex, "Client1"), add it to DB:
   Client c1 = new Client("Client1"); // and save
- Create another Client instance (ex, "Client2"), add it to DB:
   Client c2 = new Client("Client2"); // and save
- add a new BearerAccessToken associated with Client2 to DB:
   BearerAccessToken at = new BearerAccessToken();
   at.setClient(c2); // and save

(Note no tokens are associated with Client1)

the following sequence works OK:

1. delete Client2 (c2)
2. delete Client1 (c1)

This is OK, but if I start from deleting Client1 (the one with no 
tokens) I immediately see:

Caused by: <openjpa-2.4.0-r422266:1674604 fatal general error> 
org.apache.openjpa.persistence.PersistenceException: data exception: 
string data, right truncation;  table: BEARERACCESSTOKEN_PARAMETERS 
column: VALUE {prepstmnt 453026232 INSERT INTO 
BearerAccessToken_parameters (BEARERACCESSTOKEN_TOKENKEY, propName, 
value) VALUES (?, ?, ?)} [code=3401, state=22001]
	at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:5001).

I honestly do not know where to start looking. I've seen plenty of 
StackOverflow messages about the "string data, right truncation", in 
this case AccessToken.parameters map is never touched by my code, it is 
empty. And the most confusing thing why this is even happening when I 
delete a Client with no tokens associated with it.

I suspect when the Client is deleted, given a Many to One relationship 
from ServerAccessToken to Client (but no OneToMany from Client to 
ServerAccessToken), the mapping table gets refreshed in order to find 
any tokens which may be linking to Client being deleted). But that is as 
far as I can get.

Can someone please suggest why the above might be occurring, is it a 
mapping issue, or possibly OpenJPA issue ?

Many thanks, Sergey

Mark Struberg | 25 Apr 08:30 2016

[ANNOUNCE] Welcome Francesco Chicchiriccò as Apache OpenJPA committer

Good morning!

The Apache OpenJPA PMC is happy to announce that Francesco Chicchiriccò will join the project as a new committer!

Welcome to OpenJPA, Francesco!

the OpenJPA PMC

Abhishek Bafna | 5 Apr 10:30 2016
Picon

mysql master/slave connection issue

Hi,

I am trying to setup the Mysql master/slave configuration using openjpa
datasource. Version 2.2.2
Here are the properties I am setting:

*openjpa.ConnectionProperties* =
DriverClassName=com.mysql.jdbc.ReplicationDriver,Url=jdbc:mysql:replication://master,slave/db,Username=abc,Password=123,MaxActive=10,TestOnBorrow=true,TestOnReturn=true,TestWhileIdle=true,timeBetweenEvictionRunsMillis=300000,numTestsPerEvictionRun=10*openjpa**.ConnectionDriverName*
= org.apache.commons.dbcp.BasicDataSource

From this:
http://openjpa.apache.org/builds/1.2.3/apache-openjpa/docs/ref_guide_dbsetup.html

when listed driver is a *javax.sql.DataSource*, the string will be treated
as a plugin properties string, and matched to the bean setter methods of
the *DataSource* instance.

I am using BasicDataSource. When I use the single master DB, it works fine,
But the moment I setup the master,slave host, it fails with the below
exception:
-------------------------------------------------------------------------------------
Caused by: <openjpa-2.2.2-r422266:1468616 fatal general error>
org.apache.openjpa.persistence.PersistenceException: *Cannot create
PoolableConnectionFactory (Must specify at least one slave host to connect
to for master/slave replication load-balancing functionality)*
at
org.apache.openjpa.jdbc.sql.DBDictionaryFactory.newDBDictionary(DBDictionaryFactory.java:102)
at
org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:603)
at
org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1518)
at
org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:531)
at
org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:456)
at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:120)
at
org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68)
at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83)
at
org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:967)
at
org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:958)
at
org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:644)
at
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:203)
at
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
at org.apache.oozie.service.JPAService.getEntityManager(JPAService.java:500)
at org.apache.oozie.service.JPAService.init(JPAService.java:201)
at org.apache.oozie.service.Services.setServiceInternal(Services.java:386)
at org.apache.oozie.service.Services.setService(Services.java:372)
at org.apache.oozie.service.Services.loadServices(Services.java:305)
... 26 more
-------------------------------------------------------------------------------------

How can I solve this problem?

Thanks,
Abhishek
Francesco Chicchiriccò | 4 Apr 10:49 2016
Picon
Gravatar

UUID generators worth the effort?

Hi all,
in Syncope we are currently discussing [1] the option to replace our 
table generators-based id strategy to something else, based on UUID, 
which seem to offer several advantages.

I have found [2], but I would rather prefer to generated UUID values 
manually (via [3] which seems to offer better performance and more 
features than the standard JDK's).

In order to do so, I would replace the current

      <at> Id
     private Long id;

     public Long getKey() {
         return id;
     }

in  [4], backed by [5], with something like as

 <at> Id
private UUID id;

public UUID getKey() {
   synchronized(this) {
     if (key == null) {
       key = ... // generate via JUG [3]
     }
   }
   return key;
}

As Syncope supports several DBMSes, I would also like to empower the 
underlying capabilities for storing such values:

  * UUID Type for PostgreSQL [6]
  * UNIQUEIDENTIFIER for SQL Server [7]
  * RAW(16) for Oracle [8]
  * BINARY(16) with some optimizations for MySQL / MariaDB [9] or 
vanilla with H2

Do you have any suggestion about:

  (a) the way how I am planning to support UUID generation
  (b) the cleanest way to support DBMS differences (extending the 
respective DB dictionaries?)

TIA
Regards.

[1] http://markmail.org/message/fhdrwerdwdm3opdx
[2] 
http://openjpa.apache.org/builds/2.4.1/apache-openjpa/docs/jpa_overview_meta_field.html#jpa_overview_meta_gen
[3] https://github.com/cowtowncoder/java-uuid-generator
[4] 
https://github.com/apache/syncope/blob/master/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/user/JPAUser.java
[5] 
https://github.com/apache/syncope/blob/master/core/persistence-jpa/src/main/resources/META-INF/spring-orm.xml#L87-L94
[6] http://www.postgresql.org/docs/9.3/static/datatype-uuid.html
[7] http://wiki.ispirer.com/sqlways/sql-server/data-types/uniqueidentifier
[8] 
http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions175.htm#SQLRF51816
[9] https://www.percona.com/blog/2014/12/19/store-uuid-optimized-way/

--

-- 
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

Involved at The Apache Software Foundation:
member, Syncope PMC chair, Cocoon PMC, Olingo PMC, CXF committer
http://home.apache.org/~ilgrosso/

Mark Struberg | 3 Apr 12:56 2016

Re: Wrong order for delete of child when deleting parent

Can you please try upgrading to 2.4.1?
If you get the same issue in the newest version then it's much easier for us to reproduce.

It would also help if you could provide a sample project which at least contains the entity constellation in
question. It's much easier to discuss about such things in code than in mail ;)

txs and LieGrue,
strub

> Am 30.03.2016 um 19:33 schrieb tvogel <tvogel@...>:
> 
> The order of deletes for OpenJPA 2.3.x are happening in the wrong order and I
> can't figure out why.
> 
> Given these JPA mappings
> 
>    // grandparent
>     <at> Entity
>     <at> Table(name = "three_phase_motor_input")
>    public class ThreePhaseMotorInput implements IThreePhaseMotorInput,
> Serializable {
>         <at> Id
>         <at> GeneratedValue(strategy = GenerationType.IDENTITY)
>        private Long id;
>         <at> Version
>        private Integer version;
> 
>         <at> OneToOne(orphanRemoval = true, cascade = CascadeType.ALL, optional =
> true, targetEntity = UnapprovedThreePhaseMotor.class)
>         <at> JoinColumn(name = "unapproved_id")
>        private IThreePhaseMotor unapprovedMotor;
> 
>    // parent
>     <at> Entity
>     <at> Table(name = "unapproved_three_phase_motor")
>    public class UnapprovedThreePhaseMotor extends ThreePhaseMotor {
>         <at> OneToMany(orphanRemoval = true, cascade = CascadeType.ALL, fetch =
> FetchType.LAZY, targetEntity = UnapprovedThreePhaseWire.class)
>         <at> JoinColumn(name = "motor_id", referencedColumnName = "id", nullable =
> false)
>         <at> OrderColumn(name = "idx")
>        private List<IThreePhaseWire> wires;
> 
> 
>    // child - Abstract
>     <at> MappedSuperclass
>     <at> Access(AccessType.FIELD)
>    public abstract class ThreePhaseWire implements IThreePhaseWire,
> Serializable {
>         <at> Id
>         <at> GeneratedValue(strategy = GenerationType.IDENTITY)
>        private Long id;
> 
>    // child concrete
>     <at> Entity
>     <at> Table(name = "unapproved_three_phase_wire")
>    public class UnapprovedThreePhaseWire extends ThreePhaseWire {
> 
> 
> Order of SQL statements in log file when setting unapprovedMotor in
> grandparent to null
> 
>     572353115 UPDATE three_phase_motor_input SET status = ?, version = ?,
> approved_id = ?, unapproved_id = ? WHERE id = ? AND version = ?
> [params=(int) 1, (int) 8, (null) null, (null) null, (long) 896, (int) 7]
>     1683522521 DELETE FROM unapproved_three_phase_motor WHERE id = ? AND
> version = ? [params=(long) 209938, (int) 1]
>     446470297 DELETE FROM unapproved_three_phase_wire WHERE id = ?
> [params=(long) 1394]
> 
> This causes a foreign key constraint error since the child still exists when
> the parent delete statement is executed.
>    
> 
> 
> 
> --
> View this message in context: http://openjpa.208410.n2.nabble.com/Wrong-order-for-delete-of-child-when-deleting-parent-tp7589053.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.

tvogel | 30 Mar 19:33 2016
Picon

Wrong order for delete of child when deleting parent

The order of deletes for OpenJPA 2.3.x are happening in the wrong order and I
can't figure out why.

Given these JPA mappings

	// grandparent
	 <at> Entity
	 <at> Table(name = "three_phase_motor_input")
	public class ThreePhaseMotorInput implements IThreePhaseMotorInput,
Serializable {
		 <at> Id
		 <at> GeneratedValue(strategy = GenerationType.IDENTITY)
		private Long id;
		 <at> Version
		private Integer version;

		 <at> OneToOne(orphanRemoval = true, cascade = CascadeType.ALL, optional =
true, targetEntity = UnapprovedThreePhaseMotor.class)
		 <at> JoinColumn(name = "unapproved_id")
		private IThreePhaseMotor unapprovedMotor;

	// parent
	 <at> Entity
	 <at> Table(name = "unapproved_three_phase_motor")
	public class UnapprovedThreePhaseMotor extends ThreePhaseMotor {
		 <at> OneToMany(orphanRemoval = true, cascade = CascadeType.ALL, fetch =
FetchType.LAZY, targetEntity = UnapprovedThreePhaseWire.class)
		 <at> JoinColumn(name = "motor_id", referencedColumnName = "id", nullable =
false)
		 <at> OrderColumn(name = "idx")
		private List<IThreePhaseWire> wires;

	// child - Abstract
	 <at> MappedSuperclass
	 <at> Access(AccessType.FIELD)
	public abstract class ThreePhaseWire implements IThreePhaseWire,
Serializable {
		 <at> Id
		 <at> GeneratedValue(strategy = GenerationType.IDENTITY)
		private Long id;

	// child concrete
	 <at> Entity
	 <at> Table(name = "unapproved_three_phase_wire")
	public class UnapprovedThreePhaseWire extends ThreePhaseWire {

Order of SQL statements in log file when setting unapprovedMotor in
grandparent to null

	 572353115 UPDATE three_phase_motor_input SET status = ?, version = ?,
approved_id = ?, unapproved_id = ? WHERE id = ? AND version = ?
[params=(int) 1, (int) 8, (null) null, (null) null, (long) 896, (int) 7]
	 1683522521 DELETE FROM unapproved_three_phase_motor WHERE id = ? AND
version = ? [params=(long) 209938, (int) 1]
	 446470297 DELETE FROM unapproved_three_phase_wire WHERE id = ?
[params=(long) 1394]

This causes a foreign key constraint error since the child still exists when
the parent delete statement is executed.
	 

--
View this message in context: http://openjpa.208410.n2.nabble.com/Wrong-order-for-delete-of-child-when-deleting-parent-tp7589053.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Alejandro Abdelnur | 25 Feb 05:49 2016
Picon
Gravatar

getting ID only of OneToOne and ManyToOne relationships

Hello,

I've spent quite a bit of time searching around without any luck.

With OpenJPA 2.x, is it possible to get the foreign key of a OneToOne
relationship in the source without loading the target entity?

For example:

public class A {
   <at> Id
  private String id;
  private String name;
  <at> OneToOne(fetch = FetchType.LAZY)
  private B b;
  ...getters/setters
}

public class B {
   <at> Id
  private String id;
  private String name;
  ...getters/setters
}

Even if 'A a = em.find(A.class, "1")' loads the columns 'ID, NAME, B_ID'
from A if I do 'a.getB().getId()' this triggers a new query on B to get ID.

The closest related thing I found is
http://stackoverflow.com/questions/2593722/hibernate-one-to-one-getid-without-fetching-entire-object
, but this does not seem to apply to OpenJpa.

Similarly for ManyToOne relationships?

Thanks in advance.

Alejandro

Gmane