This week's book giveaway is in the Features new in Java 9 forum.
We're giving away four copies of Java 9 Revealed and have Kishori Sharan on-line!
See this thread for details.
Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Metamodel - Attribute.isAssociation()  RSS feed

 
Roy Pozarelli
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting up to speed on the JPA, in exploring things I ran into some unexpected results. In Mike Keith & Merrick Schincariol's book "Pro JPA2 - Mastering the Java Persistence API", they cover in Chapter 9 the metamodel API, in particular they take get an EntityType from the metamodel, and dump out all the attributes names, java type, etc. Now in my application I have associations between an employee, projects, departments, etc. and everything works as expected. However, when I get the Metamodel's EntityType for example the Employee (that has a Many-to-Many relationship to projects, as well as a Many-to-One relationship to departments) and I get the entity types attributes and dump out all the attributes, I've also dumped out the results of the isAssociation() on the attributes - they are always false! I understand that for BASIC attributes, but not for the relationships. Can anyone explain what is going on?



OUTPUT for Employee:
INFO: +++++++++++++++++++++++++++++++++++++++++++++++++
INFO: Employee Attributes:
INFO: Name : id
INFO: Type : java.lang.Integer
INFO: Persistent Type : BASIC
INFO: DeclaringType : EntityTypeImpl@20281766:Employee [ javaType: class MyBeans.MyEntities.Employee descriptor: RelationalDescriptor(MyBeans.MyEntities.Employee --> [DatabaseTable(employee_1)]), mappings: 6]
INFO: Association : false
INFO: Collecton : false

INFO: Name : projects
INFO: Type : java.util.Collection
INFO: Persistent Type : MANY_TO_MANY
INFO: DeclaringType : EntityTypeImpl@20281766:Employee [ javaType: class MyBeans.MyEntities.Employee descriptor: RelationalDescriptor(MyBeans.MyEntities.Employee --> [DatabaseTable(employee_1)]), mappings: 6]
INFO: Association : false
INFO: Collecton : true

INFO: Name : department
INFO: Type : MyBeans.MyEntities.Department
INFO: Persistent Type : MANY_TO_ONE
INFO: DeclaringType : EntityTypeImpl@20281766:Employee [ javaType: class MyBeans.MyEntities.Employee descriptor: RelationalDescriptor(MyBeans.MyEntities.Employee --> [DatabaseTable(employee_1)]), mappings: 6]
INFO: Association : false
INFO: Collecton : false

INFO: Name : name
INFO: Type : java.lang.String
INFO: Persistent Type : BASIC
INFO: DeclaringType : EntityTypeImpl@20281766:Employee [ javaType: class MyBeans.MyEntities.Employee descriptor: RelationalDescriptor(MyBeans.MyEntities.Employee --> [DatabaseTable(employee_1)]), mappings: 6]
INFO: Association : false
INFO: Collecton : false

INFO: Name : phoneNumbers
INFO: Type : java.util.Map
INFO: Persistent Type : ELEMENT_COLLECTION
INFO: DeclaringType : EntityTypeImpl@20281766:Employee [ javaType: class MyBeans.MyEntities.Employee descriptor: RelationalDescriptor(MyBeans.MyEntities.Employee --> [DatabaseTable(employee_1)]), mappings: 6]
INFO: Association : false
INFO: Collecton : true

INFO: Name : salary
INFO: Type : long
INFO: Persistent Type : BASIC
INFO: DeclaringType : EntityTypeImpl@20281766:Employee [ javaType: class MyBeans.MyEntities.Employee descriptor: RelationalDescriptor(MyBeans.MyEntities.Employee --> [DatabaseTable(employee_1)]), mappings: 6]
INFO: Association : false
INFO: Collecton : false

INFO: -------------------------------------------------
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to be a bug.

(btw I just fixed it, and will check in the fix to trunk (2.4) next week)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!