[EJB 3.0] - more than one, OneToOne relation gives problem
by thiagu.m
This is my bean class structure
| @Entity
| @Table(name="TBL_PRODUCTS")
| public class TblProducts implements Serializable
| {
| @Id
| @Column(name="PRODUCT_ID")
| private BigDecimal productId;
|
| @Column(name="PRODUCT_NAME")
| private String productName;
|
| @JoinColumn(name="BRAND_NAME")
| private String brandname;
|
| @OneToOne(fetch=FetchType.LAZY,mappedBy="tblProducts")
| private TblCellphone tblCellphone;
|
| @OneToOne(fetch=FetchType.LAZY,mappedBy="tblProducts")
| private TblTelevision tblTelevision;
|
| }
| -------------------------------------------------
| @Entity
| @Table(name="TBL_CELLPHONE")
| public class TblCellphone implements Serializable
| {
| @Id
| @Column(name="PRODUCT_ID")
| private BigDecimal productId;
|
| private String camera;
|
| . . .
|
| @OneToOne(optional=false)
| @JoinColumn(name="PRODUCT_ID")
| private TblProducts tblProducts;
| }
| ----------------------------------------
| @Entity
| @Table(name="TBL_TELEVISION")
| public class TblTelevision implements Serializable
| {
| @Id
| @Column(name="PRODUCT_ID")
| private BigDecimal productId;
|
| @Column(name="SCREEN_SIZE")
| private String screenSize;
|
| . . .
|
| @OneToOne(optional=false)
| @JoinColumn(name="PRODUCT_ID")
| private TblProducts tblProducts;
| }
|
|
|
Here Tblproduct is my main table , I need to make a relation with all other subcategory products table.
But when I try to add the more than one OneToOne relation within product table it gives following error
| java.lang.NullPointerException at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:135) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130) at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296) at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115) at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233) at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:869) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:407) at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126) at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:246) 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)
is there any help how to overcome this problem
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4119299#4119299
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4119299
18 years, 3 months
[EJB 3.0] - @Service + @Managment + @SecurityDomain throws Authorization
by sappenin
I have a secured EJB3 @Service bean as follows:
| @Service
| @Management(MyClassInterfaceManagement.class)
| @Local(MyClassInterface.class)
| @SecurityDomain("myrealm")
| @RolesAllowed( {
| "admin", "system"
| })
| @RunAs("system")
| public class MyClass implements MyClassInterface, MyClassInterfaceManagement
| { ... }
|
|
I have the proper things setup in my login-conf.xml file, but when I deploy this class, I get an exception stating:
| 21:11:05,887 WARN [ServiceController] Problem creating service jboss.j2ee:ear=MyEar.ear,jar=MyJar.jar,name=MyClass,service=EJB3,type=ManagementInterface
| javax.ejb.EJBAccessException: Authorization failure
| at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:113)
|
What's wierd is that I can comment out the "@SecurityDomain("mydomain")" annotation, and I don't receive the exception when I start the server, and everything works fine. This seems like a bug, although I'm not sure. Any Idea what is going on?
My assumption is that by commenting out the @SecurityDomain annotation, the Management/Service is defaulting to the security domain specified in my jboss-app.xml file in my ear, which says:
|
| <jboss-app>
| <security-domain>myrealm</security-domain>
| .....
| </jboss-app>
|
|
The applicable login-conf.xml snippets are below. Thoughts?
|
| <application-policy name = "myrealm">
| <authentication>
| <login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag = "required">
| <module-option name = "dsJndiName">java:/myDS</module-option>
| <module-option name = "principalsQuery">select PASSWORD from SYSTEM_USER where USER_ID=?</module-option>
| <module-option name = "rolesQuery">select SYSTEM_USER_ROLE.ROLE_NAME, 'Roles' from SYSTEM_USER_ROLE, SYSTEM_USER_SYSTEM_USER_ROLE, SYSTEM_USER where ((SYSTEM_USER_SYSTEM_USER_ROLE.ROLES_ID = SYSTEM_USER_ROLE.ID) and (SYSTEM_USER_SYSTEM_USER_ROLE.USERS_ID = SYSTEM_USER.ID) AND (SYSTEM_USER.USER_ID = ?))
| </module-option>
| <module-option name = "unauthenticatedIdentity">guest</module-option>
| </login-module>
| <!-- Add this line to your login-config.xml to include the ClientLoginModule propogation -->
| <login-module code="org.jboss.security.ClientLoginModule" flag="required" />
| </authentication>
|
|
|
| <application-policy name = "other">
| <authentication>
| <login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag = "required">
| <module-option name = "dsJndiName">java:/myDS</module-option>
| <module-option name = "principalsQuery">select PASSWORD from SYSTEM_USER where USER_ID=?</module-option>
| <module-option name = "rolesQuery">select SYSTEM_USER_ROLE.ROLE_NAME, 'Roles' from SYSTEM_USER_ROLE, SYSTEM_USER_SYSTEM_USER_ROLE, SYSTEM_USER where ((SYSTEM_USER_SYSTEM_USER_ROLE.ROLES_ID = SYSTEM_USER_ROLE.ID) and (SYSTEM_USER_SYSTEM_USER_ROLE.USERS_ID = SYSTEM_USER.ID) AND (SYSTEM_USER.USER_ID = ?))
| </module-option>
| <module-option name = "unauthenticatedIdentity">guest</module-option>
| </login-module>
| </authentication>
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4119296#4119296
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4119296
18 years, 3 months
[Persistence, JBoss/CMP, Hibernate, Database] - @ManyToOne uses eager fetching even if FetchType.LAZY used
by jfrankman
I have a many one to relationship and when I run a query to fetch the objects selected in the query, the related objects are still fetched even though the FetchType is lazy. Here are the mappings:
PolicyVO class maps to the FBWorker class:
public class PolicyVO implements Serializable
| {
| @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name = "AGENT", nullable = true, referencedColumnName="AGENTNO" )
| public FBWorker getAgent() {
| return agent;
| }
| }FBWorker class maps to the PolicyVO class:
public class FBWorker implements Serializable
| {
| @Id @Column(name="ID")
| public Long getId()
| {
| return id;
| }
|
| @OneToMany(fetch=FetchType.LAZY,mappedBy="agent")
| public List<PolicyVO> getAgentPolicies()
| {
| return agentPolicies;
| }
| }
Then I run the following JPA query:
select policy from PolicyVO policy
Watching the logs I see that first a query is run that selects the policy data from the database. Then, after the query is complete a query to the FBWorker table is generated and ran for every single policy object. Of course, this is unacceptable. I thought that if FetchType.Lazy is specified that the related class would not be loaded until the accessor method is called. Is there something wrong with the above mappings that makes lazy fetching impossible? I just need to fetch the PolicyVO objects without the extra overhead of fetching the related FBWorker objects.
I should also mention that the "agent" foreign key in the PolicyVO data does not map to the Primary Key of the FBWorker data, it only maps to a field (agentno) that is also unique. I know this is sloppy, but I am dealing with some legacy data here.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4119290#4119290
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4119290
18 years, 3 months