[EJB 3.0] - ManyToMany: entry on the other side of the relationship is b
by scotttam
I have a many to many relationship that is handled by a join table. Here's the simple "diagram" :
campaign -> campaign_adslot_xref <- ad_slot
When I create a new campaign object and add adslots to the relationship to get the entries in the join table created, for some reason, persist is trying to create an entry in the ad_slot table when the object already exists. Therefore, I get a duplicate key exception. When I use merge instead of persist, this works fine. I know merge has a bit of overhead and checking to see if entites exist in the db but my AdSlot object is in the persistentcontext so I am not sure why it is trying to be created.
The POJO's are:
| @Entity
|
| @Table(name="campaign")
|
| public class ParentCampaign implements Serializable {
| private long id;
|
| private Set<AdSlot> adSlots;
|
| @ManyToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY, mappedBy="campaigns")
|
| public Set<AdSlot> getAdSlots() {
|
| return adSlots;
|
| }
|
|
|
| public void setAdSlots(Set<AdSlot> adSlots) {
|
| this.adSlots = adSlots;
|
| }
|
| @Override
|
| public int hashCode() {
|
| int hash = 7;
|
| hash = 31 * hash + (int)id;
|
| hash = 31 * hash + ((null == name) ? 0 : name.hashCode());
|
| return hash;
|
| }
|
|
|
| @Override
|
| public boolean equals(Object obj) {
|
| if (obj == this) return true;
|
|
|
| if (null == obj || !(obj instanceof ParentCampaign)) {
|
| return false;
|
| }
|
|
|
| ParentCampaign other = (ParentCampaign)obj;
|
|
|
| if ((id != other.getId())) {
|
| return false;
|
| }
|
|
|
| return true;
|
| }
|
|
| }
|
| @Entity
| @Table(name="ad_slot")
| public class AdSlot implements Serializable {
| private long id;
| private Set<ParentCampaign> campaigns;
|
| @ManyToMany
| @JoinTable(name = "campaign_adslot_xref",
| joinColumns = {
| @JoinColumn(name = "ad_slot_id")
| },
| inverseJoinColumns = {
| @JoinColumn(name = "campaign_id")
| }
| )
|
| public Set<ParentCampaign> getCampaigns()
| {
| return campaigns;
| }
|
| public void setCampaigns(Set<ParentCampaign> campaigns) {
| this.campaigns = campaigns;
| }
|
Here's where I setup the newly created Campaign object with selected AdSlots.
| if (null != selectedAdSlots && selectedAdSlots.length > 0) {
|
| for (int k=0; k < selectedAdSlots.length; k++) {
|
| AdSlot as = Utils.getAdDAO().findAdSlotLazyLoadAll(new Long(selectedAdSlots[k]));
|
|
|
| if (null == currentCampaign.getAdSlots()) {
|
| currentCampaign.setAdSlots(new HashSet<AdSlot>());
|
| }
|
|
|
| as.getCampaigns().add(currentCampaign);
|
| currentCampaign.getAdSlots().add(as);
|
| }
|
| }
|
|
The findAdSlotLazyLoadAll looks like
| public AdSlot findAdSlotLazyLoadAll(long id) {
|
| return (AdSlot)em.createQuery("FROM AdSlot a " +
|
| "LEFT JOIN FETCH a.program " +
|
| "LEFT JOIN FETCH a.campaigns " +
|
| "WHERE a.id = :id ")
|
| .setParameter("id", id)
|
| .getSingleResult();
|
| }
|
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3961735#3961735
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3961735
17 years, 11 months
[JBoss Seam] - tomcat deploy
by TLex
Deploying the seam hibernate example with ant and a fresh tomcat 5.5.17 install gives me following error:
...
| INFO 30-07 20:04:15,265 (Log4JLogger.java:info:94) -Component: hotel, scope: CONVERSATION, type: ENTITY_BEAN, class: org.jboss.seam.example.hibernate.Hotel
| INFO 30-07 20:04:15,296 (Log4JLogger.java:info:94) -Hibernate Annotations 3.2.0.CR1
| INFO 30-07 20:04:15,312 (Log4JLogger.java:info:94) -Hibernate 3.2 cr2
| INFO 30-07 20:04:15,328 (Log4JLogger.java:info:94) -hibernate.properties not found
| INFO 30-07 20:04:15,328 (Log4JLogger.java:info:94) -Bytecode provider name : cglib
| INFO 30-07 20:04:15,343 (Log4JLogger.java:info:94) -using JDK 1.4 java.sql.Timestamp handling
| INFO 30-07 20:04:15,484 (Log4JLogger.java:info:94) -configuring from resource: /hibernate.cfg.xml
| INFO 30-07 20:04:15,484 (Log4JLogger.java:info:94) -Configuration resource: /hibernate.cfg.xml
| INFO 30-07 20:04:15,625 (Log4JLogger.java:info:94) -Configured SessionFactory: java:/bookingDatabase
| INFO 30-07 20:04:15,765 (Log4JLogger.java:info:94) -Binding entity from annotated class: org.jboss.seam.example.hibernate.Hotel
| INFO 30-07 20:04:15,843 (Log4JLogger.java:info:94) -Bind entity org.jboss.seam.example.hibernate.Hotel on table Hotel
| INFO 30-07 20:04:15,906 (Log4JLogger.java:info:94) -Binding entity from annotated class: org.jboss.seam.example.hibernate.User
| INFO 30-07 20:04:15,906 (Log4JLogger.java:info:94) -Bind entity org.jboss.seam.example.hibernate.User on table User
| INFO 30-07 20:04:15,906 (Log4JLogger.java:info:94) -Binding entity from annotated class: org.jboss.seam.example.hibernate.Booking
| INFO 30-07 20:04:15,906 (Log4JLogger.java:info:94) -Bind entity org.jboss.seam.example.hibernate.Booking on table Booking
| INFO 30-07 20:04:16,125 (Log4JLogger.java:info:94) -JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
| ERROR 30-07 20:04:16,156 (Log4JLogger.java:error:119) -Could not obtain initial context
| javax.naming.NamingException: Local server is not initialized
| at org.jnp.interfaces.LocalOnlyContextFactory.getInitialContext(LocalOnlyContextFactory.java:45)
| at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
| at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
| at javax.naming.InitialContext.init(Unknown Source)
| at javax.naming.InitialContext.<init>(Unknown Source)
| at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
| at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
| at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
| at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
| at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:385)
| at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:61)
| at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1928)
| at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
| at org.jboss.seam.core.Hibernate.startup(Hibernate.java:69)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
| at java.lang.reflect.Method.invoke(Unknown Source)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
| at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:32)
| at org.jboss.seam.Component.callComponentMethod(Component.java:1334)
| at org.jboss.seam.Component.callCreateMethod(Component.java:1322)
| at org.jboss.seam.Component.newInstance(Component.java:1312)
| at org.jboss.seam.Component.getInstance(Component.java:1263)
| at org.jboss.seam.Component.getInstance(Component.java:1253)
| at org.jboss.seam.contexts.Lifecycle.startup(Lifecycle.java:125)
| at org.jboss.seam.contexts.Lifecycle.endInitialization(Lifecycle.java:104)
| at org.jboss.seam.init.Initialization.init(Initialization.java:196)
| at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:32)
| at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3729)
| at org.apache.catalina.core.StandardContext.start(StandardContext.java:4187)
| at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
| at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
| at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
| at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:809)
| at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:698)
| at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:472)
| at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
| at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
| at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
| at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)
| at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
| at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
| at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
| at org.apache.catalina.core.StandardService.start(StandardService.java:450)
| at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
| at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
| at java.lang.reflect.Method.invoke(Unknown Source)
| at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
| at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)...
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3961732#3961732
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3961732
17 years, 11 months
[JBoss Seam] - Cannot find seam component <jndi problem>?
by lucas f m r
part of jboss initialize log:
...
15:03:53,203 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
15:03:53,296 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:ear=jboss-seam-usuario.ear,jar=jboss-seam-usuario.jar,name=CrudUsuario,service=EJB3 with dependencies:
15:03:53,296 INFO [JmxKernelAbstraction] persistence.units:ear=jboss-seam-usuario.ear,jar=jboss-seam-usuario.jar,unitName=userDatabase
15:03:53,781 INFO [EJBContainer] STARTED EJB: negocio.usuario.CrudUsuario ejbName: CrudUsuario
...
but when i thi the submit i´m getting the follow exceptions:
Caused by: javax.naming.NameNotFoundException: CrudUsuario not bound;
Caused by: org.jboss.seam.InstantiationException: Could not instantiate Seam component: CrudUsuario;
Caused by: javax.faces.el.EvaluationException: Exception while invoking expression #{CrudUsuario.persistir};
javax.faces.FacesException: Error calling action method of component with id _id0:_id6
and the components.xml:
false
#{ejbName}/local
tanx
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3961731#3961731
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3961731
17 years, 11 months