No PK nor FK - C_Order

555 views
Skip to first unread message

Daniel Tamm

unread,
Dec 14, 2014, 12:17:10 PM12/14/14
to idem...@googlegroups.com
Hi!

I'm developing plugins for iDempiere and I keep getting these error messages on a regular basis. It seems as if the errors occurs when modules are started / imported in the wrong order. Restarting a reordering the start levels fixes these problems many times. However, it would be nice to know the cause of this if someone has a better clue than I do. Typically this error doesn't occur when I run iDempiere in eclipse but it occurs when I deploy.

caused by: java.lang.IllegalStateException: No PK nor FK - C_Order
        at org.compiere.model.PO.setKeyInfo(PO.java:1691)
        at org.compiere.model.PO.load(PO.java:1448)
        at org.compiere.model.PO.<init>(PO.java:202)
        at org.adempiere.model.GenericPO.<init>(GenericPO.java:81)
        at org.compiere.model.MTable.getPO(MTable.java:427)
        at org.compiere.model.Query.list(Query.java:268)

Jan Thielemann

unread,
Dec 16, 2014, 9:58:36 AM12/16/14
to idem...@googlegroups.com
Are you querying custom models? I don't see why idempiere shold use GenericPO for C_Order table since there is MOrder :/

Daniel Tamm

unread,
Dec 16, 2014, 10:05:13 AM12/16/14
to idem...@googlegroups.com
In this case I'm not using custom models. I suspect though that the problem has something to do with the start order of my modules.
The exception in my example comes from a custom module that tries to load an MOrder object. I got everything working in the end without I really know what I did except for restarting and reordering, uninstalling modules and installing modules. Unless I find out what the problem is, it's always a gamble to deploy modules to a production server.

If anyone knows about how the modules load and what the start order must be I would be very happy to learn more about it :-)

/Daniel
--
You received this message because you are subscribed to the Google Groups "iDempiere" group.
To unsubscribe from this group and stop receiving emails from it, send an email to idempiere+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/idempiere/d3f4affe-fea7-4485-9ec8-9d2e75a14bfc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 

--
Notima AB
Lärjungevägen 6
SE-136 69 Vendelsö
Tel: +46 8 776 31 30 Fax: +46 8 712 95 73
Web: http://www.notima.se/
--

Jan Thielemann

unread,
Dec 16, 2014, 10:35:50 AM12/16/14
to idem...@googlegroups.com
I once had a similar problem where i got errors when i startet my plugin in default start level. setting it to something like 7 or so fixed the problem but i was never able to reproduce it since then

Heng Sin Low

unread,
Dec 16, 2014, 10:51:44 PM12/16/14
to idem...@googlegroups.com
Is that errors comes from code in your  bundle activator ? If yes, you can use Adempiere.addServerStateChangeListener to execute your code after the Adempiere core have been started ( for reference, see org.adempiere.plugin.utils.AdempiereActivator ).

Also, if your code depends on the availability of certain service, you can use the ServiceTracker for that. Again, you can find reference for that at org.adempiere.plugin.utils.AdempiereActivator

Daniel Tamm

unread,
Dec 17, 2014, 4:12:26 AM12/17/14
to idem...@googlegroups.com
Thanks for the suggestions. Sounds exactly what I was looking for.

The problems all points to things starting in the wrong order and to be able to guarantee that my modules are started after the core I think is the solution.

The errors has also occurred in the core classes when my modules has started before the core.

/Daniel

For more options, visit https://groups.google.com/d/optout.

Daniel Tamm

unread,
Dec 22, 2014, 7:25:12 AM12/22/14
to idem...@googlegroups.com
This is so wierd. I've tried everything I can think of. Manually uninstalling the modules. Installing the modules after the server is started. Setting start levels. Starting/Stopping, adding ServiceTrackers and I still get this in one of my modules:

caused by: java.lang.IllegalStateException: No PK nor FK - M_Product_Category
        at org.compiere.model.PO.setKeyInfo(PO.java:1691)
        at org.compiere.model.PO.load(PO.java:1283)
        at org.compiere.model.PO.<init>(PO.java:204)
        at org.adempiere.model.GenericPO.<init>(GenericPO.java:71)
        at org.compiere.model.MTable.getPO(MTable.java:396)
        at org.compiere.model.X_M_Product.getM_Product_Category(X_M_Product.java:1013)
        at org.notima.idempiere.businessobjects.ProductFinder.convert(ProductFinder.java:158)
        at org.notima.idempiere.businessobjects.ProductFinder.getProductInfo(ProductFinder.java:187)

What is the core reason to this error message? Some setting has most probably not been initialized... the question is which one?

Daniel Tamm

unread,
Dec 22, 2014, 11:50:14 AM12/22/14
to idem...@googlegroups.com
An interesting thing is that this error ONLY occurs on the deployed server, ie the same configuration running in Eclipse always works (same database).
I can even replicate the error to other servers by installing the same modules.

I'll look deeper into this and if I find solutions I'll let you know.

Carlos Antonio Ruiz Gomez

unread,
Dec 22, 2014, 12:00:17 PM12/22/14
to idem...@googlegroups.com
Daniel, for those errors that happen in server and not in eclipse - the most helpful tool is the remote debug - I struggled with some of those errors past week - and remote debug was able to show me what was happening on server.

You just need to start the server with debug at the end like:
./idempiere-server.sh debug

And point your remote app in eclipse to the server IP and port 4554 (and open the port in firewall or as in my case use a ssh tunnel for that).

If you want to debug some initial classes (like the OSGi loaders) then maybe you better change in idempiere-server.sh the flag suspend=n to suspend=y

Regards,

Carlos Ruiz

Daniel Tamm

unread,
Dec 22, 2014, 3:49:04 PM12/22/14
to idem...@googlegroups.com
Thanks for the helpful info :-)

Perhaps I have an old version of idempiere-server.sh. I had to add

-Xdebug -Xrunjdwp:transport=dt_socket,address=4554,server=y

to the last line of the script. Other than that it worked like a charm to debug remotely.

What I found was that the Env.getCtx() isn't propagated to my module for some reason which makes certain functions fail (functions that depend on the Ctx).

Now I have a clue where to fix. If there's a proper way to get the ctx from a module I'd be happy for any information.

Daniel Tamm

unread,
Dec 22, 2014, 4:06:09 PM12/22/14
to idem...@googlegroups.com
The following code before calling the previously failing function solved my problem:

        ctx = Env.getCtx();
        Env.setContext(ctx, Env.AD_CLIENT_ID, s_clientId);

The s_clientId I had to set manually. Perhaps not the optimal solution but it works for now.
Env.getCtx() returned an empty ctx but setting the Env.AD_CLIENT_ID made the PO-lookup work.

Thanks for all the help!
Reply all
Reply to author
Forward
0 new messages