- This topic has 7 replies, 3 voices, and was last updated 18 years, 4 months ago by Brian Fernandes.
-
AuthorPosts
-
thurisazMemberHi there,
currently I’m testing the myEclipse-Hibernate-Support.
I’ve already managed it to realize a one-to-one connection with two associated classes (i.e. saving an object cat and catowner to a database). This works problery. Now I’m trying to realize a one-to-many-connection.
The scenery:
I have an articles which has normal attributes like name, date of creation etc. and a Vector which stores Article-Components. The Text-Components have two attributes: a headline and the component-text (both attributes are Strings). Now I’m trying to create a Hibernate-Mapping that creates java-classes from the Database-Tables. I want to have an article with the “text-components”-vector and of course the text-components (without the association to the article). But I have no Idea how I should do this.
Whenever I create the hibernate-java-classes from the database I’ll just get articles with no associations to the text-components and the text-component-class has an article-atttribute. But I want it excatly the other way round
Can somebody help (Database is Postgresql)?
The SQL-Code for this is:
CREATE TABLE normalArticleComponents ( articleComponentID SERIAL PRIMARY KEY UNIQUE, articleID INTEGER REFERENCES articles ON UPDATE CASCADE ON DELETE CASCADE, componentName TEXT NOT NULL, componentText TEXT NOT NULL, componentType TEXT NOT NULL ); CREATE TABLE articles ( articleID SERIAL PRIMARY KEY UNIQUE, isPublic BOOLEAN NOT NULL DEFAULT false, isTemplate BOOLEAN NOT NULL DEFAULT false, language TEXT NOT NULL, headline TEXT NOT NULL, detail TEXT NOT NULL );
thurisazMemberAccording to this thread https://www.genuitec.com/forums/topic/hibernate-support-2/&start=0&postdays=0&postorder=asc&highlight=
it seems so that many-to-one-associations are not suppordet by myeclipse. is this correct?If it is correct I have a new question: I know that I should not change the hibernate.cfg.xml, because it is synchronized but can I add one-to-many-associations to the hibernate *hbm.xml-files manually? So, can I add the one-to-many-associations after the automated code-gerneration by hand?
support-jeffMemberThe thread does not mention m2o associations at all. In fact m2o is supported. If you have a FK in the database on a table that you then generate Java class and hibernate mapping from, the generated code will possess a simple reference to the exporting table. As you surmise, the converse (o2m) is not yet supported, nor are the other more (or less) complex relationships. These will be supported in a future release. You can manually add them as you need now, but beware that if you re-generate the mappings at any point your changes will not be preserved.
thurisazMemberOkay – I think that I missunderstood the difference between o2m and m2o – thanks!
thurisazMemberdid I understand it correct, that one-to-many relationships are now supported in the newest version of myEclipse which is aviable since yesterday???
support-jeffMemberNope, not yet. “Wait for it…..”
thurisazMember@support-jeff wrote:
Nope, not yet. “Wait for it…..”
Is it now possible to do many-to-one-relations in MyEclipse 5?
I still have the same issue, that I have 1:m or n:m relations in a database but I can not map them with MyEclipse to simple Hibernate-Pojos.
Is this feature now implemented?
Brian FernandesModeratorOur mapping tools do generate 1:m relationships.
However, user control over the relationships generated is not yet implmented but is on the cards for the next release.
Sorry for the inconvenience caused,
Best,
Brian. -
AuthorPosts