Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Generate Entities from Tables (Postgres)
Generate Entities from Tables (Postgres) [message #829461] Mon, 26 March 2012 10:18 Go to next message
shalin lazar is currently offline shalin lazarFriend
Messages: 18
Registered: February 2012
Junior Member
I believe I may have initially posted in a wrong thread. Tried to post a link to thread, but I can't do that ... so I'll just quote myself. Apologies in advance.

shalin lazar wrote on Sat, 24 March 2012 07:18
Hi all,

I'm not sure where to ask this, so if I'm in the wrong place, apologies in advance.

I have built a large database in PostgreSQL 8.4, with quite a few Stored Functions, Triggers, etc. in order to increase the performance of my application and for functional requirements such as avoiding gaps in some sequences.

I've build Java EE applications before on NetBeans, but have chosen Eclipse for obvious reasons. I've been following the following tutorial:

programming[dot]manessinger[dot]com[slash]tutorials[slash]an-eclipse-glassfish-java-ee-6-tutorial;

... in order to get around some specifics, but I've run into a problem at the first hurdle which I cannot seem to figure out.

When generating entities from my database, the resulting Entity Beans are full of errors: some tables are not even generated even though I selected all tables in the wizard.

I think the main reason is that I do not have a fixed structure of tables in my database. For example, some tables have up to 4 columns as a collective primary key, while others have just a column and a row to store a count variable. The database indexing is fine as it is and can run without any problems on its own. I'm mostly planning on building the front end (Swing) and finishing off the smaller (quicker) business logic through Session and Message-Driven beans.

So that is a basic intro of the state I'm in. There are quite a few errors ... I'll list the ones I've noted as of now:

1) Some tables are not generated as entity beans.
2) Some associations generate naming errors: So far, I've only noted SOME @ManyToOne associations. I'll go into more detail here.

In the Table Associations frame of the Entity Generation wizard, I've noted a ManyToOne relation. The Table join section seems fine, as do the properties of both tables involved.

Eg: accountTransactCenter.currencyId = currency.id

However, AccountTransactCenter.java has the following error:

//bi-directional many-to-one association to Currency
@ManyToOne --> error
@JoinColumns({})
private Currency currency;

Mouse-over the error: Join column "currency_id" cannot be resoved on table "accountTransactCenter"

Now, I made a few errors in my DB development. Mainly, name errors. I followed java method style, starting all DB identifiers with lowercase with an proceeding word beginning with an upper case. Postgres supports identifiers with uppercase characters by double-quoting them. As I was using a GUI client in pgadminIII, I only noticed this when I had done quite a bit of work.

Secondly, and I do not think this is an error, I name my foreign keys as such:

localTable_foreignTable_foreignTableColumnName.

This could be the only reason I can think of as to why currency_id was raised as an error, as I had not entered any such name into a column or table name. Are my suspicions correct? So, for the example given, the foreign key in accountTransactCenter would be:

fki_accountTransactCenter_currency_id (fki is generated by Postgres).

Other than this, I haven't found anything else. I know I should have tried an easier example before building my whole database, but is there any way around these issues?

Thanks and best regards.


shalin lazar wrote on Mon, 26 March 2012 03:59
Bump Smile

I should state that I'm using EclipseLink for JPA 2.0 on Indigo. I'm using Postgres' jdbc4 driver which is working well. Can't seem to figure out why I'm getting this error both on Windows and Linux (It was a long shot I know ... but should give you an idea of how much help I could use. I really have no clue how to solve this).

I will try using Hibernate as my persistence provider, then an older TopLink. Hopefully, something will come through.

I should also add that I'm running a glassfish 3.1.1 application server.

Any help/comments would be greatly appreciated.

Thanks.



Basically, I've built a postres 8.4 database, but not all Entity classes are generated in my EJB project, and there are some @ManyToOne association errors.

Your help will be much appreciated.

Best regards.
Re: Generate Entities from Tables (Postgres) [message #829589 is a reply to message #829461] Mon, 26 March 2012 14:16 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
Hello,

I can only comment on the currency mapping. It's definition of join columns:
@JoinColumns({})
Forces it to use the default. If Currency has an "id" field, the default will be "CURRENCY_ID", which might not exist in accountTransactCenter if you have a different field as the foreign key.

This does not seem to be JPA errors though, but entity generation, so using a different JPA provider is not likely to help. I'm not sure where this was originally posted, but sounds like it should go in the Dali forum since EclipseLink doesn't actually generate Entities from the tables.

Best Regards,
Chris
Re: Generate Entities from Tables (Postgres) [message #829678 is a reply to message #829589] Mon, 26 March 2012 16:27 Go to previous messageGo to next message
shalin lazar is currently offline shalin lazarFriend
Messages: 18
Registered: February 2012
Junior Member
Hi Chris,

Thanks for your response.

I did a bit of testing on my own, and yes ... you are right. I had initially tried changing the name of the foreign keys, but that didn't seem to do much help. Then, I did as you said and changed the column names of say accountTransactCenter to currency_id ... and it has worked.

I never read or knew anything of this nature till this testing, and I had built quite a few EJB project till this date (albeit none of this size).

I have around 240 tables in my database, so I broke them up into parts of 50. I.e. generated 50 Entity Beans at a time. It seems to have done the trick. Is there some sort of variable/field that you would have to enter into the JPA Settings to limit this amount?

Busy day tomorrow ... got to get this up and running asap.

Thanks.
Re: Generate Entities from Tables (Postgres) [message #830066 is a reply to message #829589] Tue, 27 March 2012 06:18 Go to previous message
shalin lazar is currently offline shalin lazarFriend
Messages: 18
Registered: February 2012
Junior Member
Chris Delahunt wrote on Mon, 26 March 2012 10:16
This does not seem to be JPA errors though, but entity generation, so using a different JPA provider is not likely to help. I'm not sure where this was originally posted, but sounds like it should go in the Dali forum since EclipseLink doesn't actually generate Entities from the tables.

Quick question: So from your comment, its seems as though EclipseLink just manages persistence; What then generates the entities?

Another one: Is this a problem specific to postgres? I've developed a few EJB apps with MySQL and never ran into this problem. Or is it just a newer version of the Entity generator?

If there's a quick fix, other than going into each and every table, changing column names, please let me know. Because there are a few tables that have more than one column referencing the same table and column:

Eg. accountTransactCenter.accountId -> account.id and accountTransactCenter.contraAccountId -> account.id

How should I name the columns in this case?

[Updated on: Tue, 27 March 2012 08:58]

Report message to a moderator

Previous Topic:DatabasePlatform: convert varchar to nvarchar for ms sql server
Next Topic:Configure Dali Entitty Generator to create all @column annotations
Goto Forum:
  


Current Time: Thu Nov 27 08:42:40 GMT 2014

Powered by FUDForum. Page generated in 0.03453 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software