[EJB 3.0] - @SecondaryTable. How to use it?
by NigelWhite
How can I use @SecondaryTable?
I have a Contact entity which defines a person's email, phone etc. There may be several of these pointing to a single Person entity.
Because a person may belong to several organizations, and have several contactable personas.
So. I want to create a ContactPerson entity from two tables.
It seems that I have to have the primary table as the Person table because there are many Contacts, and they have a foreign key which points to the Person's primary key, and it only works this way round, the seconary pointing to the primary. You can't have a FK on the primary pointing to the secondary!!!
But obviously, the @Id field cannot be the id field of that primary table, the Person table. Because it will be repeated several times, once for each Contact that's linked to it.
so I have
| @javax.persistence.Table(name="Person")
| @SecondaryTable(name="ContactDetails",
| pkJoinColumns=@PrimaryKeyJoinColumn(name="person_id"),
| uniqueConstraints = @UniqueConstraint(columnNames={"person_id", "player_id"})
| )
| public class ContactPerson extends CompositeEntity implements Serializable
| {
| private Long id;
| @Column(table="ContactDetails", name="id")
| @Id
| public Long getId() {
| return id;
| }
| public void setId(Long id) {
| this.id = id;
| }
| ...
|
And I think it's that ID that's causing the problem.
With this, I get
| org.hibernate.MappingException: Unable to find logical column name from physical name id in table person
| org.hibernate.cfg.Mappings.getLogicalColumnName(Mappings.java:514)
| org.hibernate.cfg.Ejb3JoinColumn.linkValueUsingDefaultColumnNaming(Ejb3JoinColumn.java:270)
| org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:214)
| org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1253)
| org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1101)
| org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:567)
| org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:508)
| org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
| org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
| org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
| org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
| org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233)
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4054833#4054833
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4054833
18Â years, 10Â months
[JBoss AOP] - Re: Maven 2 plugin?
by stalep
i added maven-jbossaop-plugin to the aop svn respository. i guess we'll move it to the jboss-plugins repository when the time is right, but i just added it here so the hardcore aop users could test it out :)
small howto:
1. get the source and run (in the maven-jbossaop-plugin folder): mvn install (this will build the plugin and put in your local repo)
2. add to the pom.xml where you want to use aopc:
| <dependency>
| <groupId>jboss</groupId>
| <artifactId>maven-jbossaop-plugin</artifactId>
| <version>1.0-SNAPSHOT</version>
| </dependency>
| <dependency>
| <groupId>jboss</groupId>
| <artifactId>jboss-aop</artifactId>
| <version>2.0.0.alpha2</version>
| </dependency>
| <dependency>
| <groupId>jboss</groupId>
| <artifactId>jboss-common</artifactId>
| <version>4.0.2</version>
| </dependency>
| <dependency>
| <groupId>concurrent</groupId>
| <artifactId>concurrent</artifactId>
| <version>1.3.4</version>
| </dependency>
| ...
| <plugins>
| <plugin>
| <groupId>jboss</groupId>
| <artifactId>maven-jbossaop-plugin</artifactId>
| <!-- include this if you want to always run aopc after compile
| <executions>
| <execution>
| <id>aopc</id>
| <configuration>
| <aoppath>src/main/resources/jboss-aop_blabla.xml</aoppath>
| </configuration>
| <goals>
| <goal>aopc</goal>
| </goals>
| </execution>
| </executions>
| -->
| </plugin>
| </plugins>
|
- the "configuration" tag is only show as an example and is not needed if you only have a file named jboss-aop.xml in src/main/resources.
if the execution tag is omitted you have to run: mvn compile and then mvn jbossaop:aopc to aopc the files.
almost all options supported in ant is supported here, take a look at the javadoc for more info.
test it out and let me know how it works. i need to learn a bit more about maven before im comfortable letting this out :)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4054822#4054822
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4054822
18Â years, 10Â months