EJB representing optional relationship
Hi,
I was wondering how does EJB 2.0 deployment descriptor handles the 1 to 1/0 relationship between 2 entites. For example, 1 course can have 0 or 1 textbook. In this case, textbook is optional and might be represented as null in the database.
The following represents 1-to-many relationship, how can I define 1-to-1/0 relationship? Please help. Thanks.
<relationships>
<ejb-relation>
<ejb-relation-name>Textbook-Course</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>Textbook-has-Course</ejb-relationship-role-name>
<multiplicity>many</multiplicity>
<relationship-role-source>
<ejb-name>TextbookBean</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>course</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>Course-has-Textbook</ejb-relationship-role-name>
<multiplicity>one</multiplicity>
<relationship-role-source>
<ejb-name>CourseBean</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>textbooks</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
</relationships>
hi,
I think you can use 1-1 relation for your case. It will also take care of 1-0.
You just need to update the Textbook-Course multiplicity tag.
Set multiplicityto one
If there is no textbook in a course the Collection will be empty. if you strictly want to model 1 -1/0 , then no need to using Collection in following tag. Just use the type of TextBookbean's remote interface.
<cmr-field>
<cmr-field-name>textbooks</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>I am using the same technique in our application . We take help of model 1-1 for 1-0 type of relation.
regards,
Amit
Similar Messages
-
When I use IDEA to generate my session beans it appends to a single ejb-jar.xml file in a single META-INF folder. This file gets bigger for each EJB I add.
On the other hand, the ant <ejb-jar> task looks for a file called [ejbname]-ejb-jar.xml for each and every ejb I have.
So, is it possible to package multiple EJB's in one ejbjar? I just barely know what I'm doing. Should I be using the <ejb-jar> task in the first place? Am i using IDEA wrong?
How many ways can i structure an ejbjar?There is one ejb module with multiple beans in it but only one ejb-jar.xml that it creates for me.
So, is it possible to package multiple EJB's inone
ejbjar? I just barely know what I'm doing. ShouldI
be using the <ejb-jar> task in the first place? Ami
using IDEA wrong?Maybe. Does it create a new jar for each EJB ?
Then it seems that you create a new EJB module for
or each EJB, which is, of course, wrong.
Create just one EJB module and put all beans in that
module. -
EJB 3.0 relationship mapping fail to remove foreign table record
I have a Customer class which declare the relationship as follow:
@OneToMany(cascade={CascadeType.ALL}, mappedBy="book")
private List<Book> book;
At my Phone class I declare the relationship as follow:
@ManyToOne
private Customer customer;
Whenever I remove the a book, the book is being removed as I iterate the List<Book> collection using the get method. But in the database, the records still exist!
Anyone can explain where has gone wrong?Try flushing the entity manager directly after removing the book. But i think the book will still remain as you are not calling the remove method. In your case the relation maybe removed. you have to remove the book from the book class itself.
Edited by: rebin on Sep 23, 2007 4:21 AM -
How do I add -Xlint option to the EJB compilation process?
Hello,
I have a 4 server node clustered environment. I am running WebLogic
Server 9 MP 2 on Windows server 2003 Enterprise Edition SP 2. I am
running Sun JDK 1.5 update 11. When the EJBs are compiled Isee the
following message in the server logs (for every EJB):
####<Nov 16, 2007 6:15:09 PM CST> <Info> <EJB> <machine1> <wlserver1>
<[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default
(self-tuning)'> <<WLS Kernel>> <> <> <1195258509358> <BEA-012033>
<Compiling generated EJB classes produced the following Java compiler
output:
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
I checked through the documentation, and the extra EJB compiler options
don't offer the -Xlint option. I checked the Java documentation and it
does support that option. My servers are using the default javac
compiler. I have not figured out how I can add the -Xlint option to the
server compilation process, in order to get the additional information I
need to diagnose the problem. Please help.
http://e-docs.bea.com/wls/docs92/ConsoleHelp/pagehelp/Corecoreserverserve
rconfiggeneraltitle.html#advancedAttributes
Thanks,
pimyI love being able to have a group contact list on my device.
You can go to Contacts>Click on the icon right below the contacts with 2 people>Select the green plus sign in the upper right hand corner>Create a group name and then go thru the contact list to add up to 20 contacts for the group.
This will help you get the group contacts added again.
Tamara H.
Follow us on Twitter @VZWSupport -
Classes across packages , how to represent relationship in metadata
I have 2 packages. Package "sample" is having classes Log and sample.jdo.
Packae docmanager contains Attribute class and docmanager.jdo.The class Log
has a collection of Attribute class.
How do I represent this relationship in metadata file sample.jdo.
We can't use system.jdo due to our design constraints.
Please suggest the way :)
-SantoshThere is no requirement that all related persistent classes be in the
same jdo file. Just use fully-qualified class names whenever referencing
a persistent class that isn't in the package named by the current
<package> element. -
Using an EJB as a source for a Model
Hi,
Before starting with this post content it might be helpful to give you the desired output of what I am trying to do. Basically I need to have an HTML table that is populated from an EJB.
The current proposed solution is as follows: the Model that is associated with a TiledView will be used as client for the EJB. The Model will make use of the methods in the EJB to get different java.util.Collection objects for different Helper classes based on the find criteria.
For example, if the EJB represent a book and there is a home method to retrieve a list of books based of the book category. In this case the Model will act as a client of the EJB, retrieve the list of books and use the different methods in the Model, such as insert and retrieve, to get the list of books and to add a book up on request.
I know that my post might not be clear. But as I said, all that is needed is to have a TiledView that displays books information, which are retrieved from an EJB, and allow a user to select a book to display its information.
My suggested solution could be completely wrong, not visible and reflect a bad design. Please if any one went through such a situation give me a hint.
Regards,
Basil MahdiBasil,
This is some material I snipped from an internal Sun forum I posted to regarding a simple EJB Jato integration example.
I hate to give just any EJB JATO example because frankly there are so many different use cases with EJBs that no one example will match up against your needs. You can use an EJB
- in a Custom Model Operation you can encapsulate an EJB Method invocation
- in a Custom Command you can encapsulate any arbitrary code include calling an EJB
- as the backingstore for a CustomModel
- use a BeanAdapterModel to adapt to the value/transfer beans which are uses as parameters or return values of EJB methods
- use an ObjectAdapterModel to adapt an EJB directly by assigning the EJB reference in setObject() in the constructor of the OAM
As you can see, an EJB is just another business object API...its just that you acquire the reference with a few lines of ugly JDNI and Home interface APIs.
Nevertheless, here is some guidance. I would like to reinforce that there is no direct solution for adapting an EJB from BAM; EJBs are not JavaBeans. What is a solution is to have the parameters or return values of your EJBs use value/transfer object patterns in the form of JavaBeans. The BAM may be used to adapt to these parameters or return value of the EJB.
In short, when using BAM in a tileview to work with an EJB, there is little difference than using BAM at any other time, you the developer, must manage/code the placement of the EJB parameters directly into the BAM or in a scoped attribute to be used by the BAM.
In another example, you may have a SLSB which models an employee called EmployeeSupport. You may have a transfer object (JavaBean) of type EmployeeRecord. You may have operations on the EJB including:
public EmployeeRecord findEmployee(String employeeID);
public EmployeeRecord[] findEmployees(String location);
public void updateEmployee(EmployeeRecord);
One could create a BAM in the studio called EmployeeModel
You would set the JavaBean class to EmployeeRecord
You would run the Design Action to bootstrap the properties of EmployeeRecord as fields on the model
Now you have a model which is ready to adapt to EmployeeRecord bean.
Feel free to add material to the EmployeeModel to make a richer API; for instance you could encapsulate some EJB'ish code in their to act as a service locator for a EmployeeSupprt SLSB.
protected static EmployeeSupport support;
static {
javax.naming.Context context = new javax.naming.InitialContext();
Object objref = context.lookup("ejb/EmployeeSupport");
EmployeeSupportHome home = (EmployeeSupportHome)
javax.rmi.PortableRemoteObject.narrow(objref,EmployeeSupportHome .class);
support = home.create();
public static EmployeeSupport getEmployeeSupport() {
return support;
If you really wanted to hide the EJB'ishness of the EmployeeSupport you could even wrap the behavior and handle exceptions, etc.
public static EmployeeRecord findEmployee(String employeeID) {
return getEmployeeSupport().findEmployee(employeeID);
public static EmployeeRecord[] findEmployees(String location) {
return getEmployeeSupport().findEmployees(location);
public static void updateEmployee(EmployeeRecord record) {
return getEmployeeSupport().updateEmployee(record);
You could even help the view developer latch EJB transfer objects into the model for adaption; saving them from the effort
public void adaptEmployee(String employeeID) {
setBean(findEmployee(employeeID));
public void adaptLocation(String location) {
setBean(findEmployees(location));
public void save() {
updateEmployee((EmployeeRecord)getBean());
Create a search ViewBean, place a text field on it for an EmployeeID and button labeled Find. Leave the EmployeeID model binding default (to use a DefaultModel memory model). Open the handle request event method on the viewbean for the Find button.
public void handleFindRequest....{
EmployeeModel model = .....;
model.adaptEmployee(getEmployeeIDChild().getValue());
// display Edit page which has fields for editing the employee record
Create an edit ViewBean, with editable fields bound to the EmployeeModel; add an button labeled update
public void handleUdpateRequest....{
EmployeeModel model = .....;
model.save();
// do whatever is next ....
Notice that the we are jumping across request boundaries in this example. Using just default model reference configurations, the EmployeeModel will be created brand new during the Update request and there will be no bean currently adapted. Most likely, you would want to have the model (and hence its adapted bean) stored in HttpSession across at least these related requests. In this case the model reference used by the search ViewBean would have "store in session" true. and the model reference in the edit ViewBean would have "look in session" true.
What we recommend is that someone who understands the business tier design take the responsibility to create a set of "business delegates" as JATO models. An advanced technique would be to encapsulate these models in a component library JAR which multiple web applications can reuse. As you can imagine, there are so many ways to do the same thing. You could just as easily make a CustomModel or SimpleCustomModel to adapt to your EJB. You can also, if your EJB uses primitives or JavaBeans (or graphs of JavaBeans) for all parameters, use the ObjectAdapterModel to directly connect to an EJB. -
Hi,
i am doin java client proxy in XI.i ve imported the beans generated from XI into an EJB project in NDS and have changed the ejb-jar.xml accordingly.However the "BUILD EJB ARCHIVE" option is not enabled.Can anyone help?
Regards,
DivyaHI
GOOD
GO THROUGH THESE LINKS
http://help.sap.com/saphelp_nw04/helpdata/en/86/58cd3b11571962e10000000a11402f/content.htm
http://www.sapgenie.com/xi/
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/f272165e-0401-0010-b4a1-e7eb8903501d
THANKS
MRUTYUN -
In SAPNetweaver developer Studio, I am unable Build EJB Archive
Hi,
In EJBModuleProject the Build EJB Archive option is diabled.Even all the ejb's have ejbCreate() method still the Build EJB Archive option is diabled.Also the ejb-jar.xml file is not showing its beans in explorer even it contains description for all the ejbs. Let me know is there any solution for this.Hi,
the odds are, NWDS will only recognize EJB, which strictly adhere to (its) EJB rules, means created in the GUI, implementing directly the required interfaces, having methods, which throw RmiException, etc. If, by chance, your EJBs do not adhere to these rules, proceed as follow:
1. Create a dummy EJB, say DummyEjb by NWDS means and "secure" the xml description of it as template
2. Take the xml template from 1 and create ejb descriptors for your real EJBs and paste them to the ejb-jar.xml
This way you should get correct descriptors for your EJBs and be able to create the ejb module archive.
Regards
Gregor -
Build ejb archive disabled - NWDS
hi ,
I am building an adapter module as per:
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/da5675d1-0301-0010-9584-f6cb18c04805
But Build EJB Archive option is disabled to create the jar files. I tried many options but still the same.
Can someone help me with what to do?
Can we develop the adapter module using the WSAD(Websphere Application Developer Studio)?Hi Satya,
just copy your java code at in someother place.....then delete your EJB prj...NWDS will ask for deleting contents....choose delete content also option.. delete both projects......
Now start creating a fresh EJB Project with a new name.....follow the "how to create adapter module" document......do all the steps.......
Then you will be able to build your ejb archive by right clicking your ejb project..
Thanks,
Rajeev Gupta -
hi ,
I am building an adapter module as per:
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/da5675d1-0301-0010-9584-f6cb18c04805
But Build EJB Archive option is disabled to create the jar files. Can someone help me with what to do ...
thank youHi Raj,
1) Are you using NWDS for developing,
If so open J2ee development perspective from menu option windows in NWDS. In left side, choose J2ee explorer tab. Here, it shows your EJB project. Right click on it and choose Build EJB archive.
2) Check whether you have opened the right perspective when you are trying to build the EJB archive.
3)Check this : The file ejb-jar.xml does not know what is the class and rest of the details for your ejb. For checking this, go to J2EE explorer and you will see ejb candidates.Right click on it and select add to ejb-jar.xml. You should now see the Build EJB Archive option enabled.
Regards
Agasthuri Doss -
Is the EJB Finder Find By Where supported?
I've been developing applications using JBOSS application server and it has Find-By-Where and Find-By-Where-Order-By as custom EJB finder options. This is where I can send in the where clause dynamically into the CMP layer and in the latter case order by a specific column set. I can't seem to do that in orion-ejb-jar.xml.
Is this a supported tag? If not can it be added?
Since the CMP EJBs Finders must be strictly defined ahead of time (unless you want to write the SQL your self - then why bother) on what you can and can't search on it's a real pain to add new parameters to searches. I've hacked it together and done a partial finder like this for now:
<finder-method partial="true" query="(number = $1 OR $1 IS NULL) AND (UPPER(last_name) LIKE $2||'%' OR $2 IS NULL) AND (UPPER(first_name) = $3 OR $3 IS NULL)>
Thanks,
RichPlease look at a list on the Right side of the Forums Home page, Select Enterprise Java Beans from the list and press the GO button... You get the EJB forum list
-
Represent hierarchical structure in graphical structure (by reports?)
Hi
I have a parent child relationship where I am using sys conect by path to represent the relationship. Can I display this relationship in graphical structure in Orace Reports?Why does Java follow the hierarchical structure i.e
Object class is the root class which is extended by
all classes by default..
Can anybody tell the reason for this.It's for technical reasons. In this way any class and class hierarchy always have a known super-superclass namely Object. This means that API's can be written assuming this class only and they will then work with objects of any class. Examples of this are the Collections and Swing. -
Plea for example - Many-to-Many CMP EJB
I am attempting to create an EJB that uses Container Managed Persistence,
but my situation seems to be an odd one. The EJB needs to have a
Many-to-Many relationship to itself, because the object is Hierarchical.
Because this is my first EJB I am having a hard time with all of the
deployment descriptors.
I am asking for an example of any Many-to-Many EJB relationship that uses
Weblogic's built-in link table creation to make the relationship (that
works). I realize that there are confidentiality issues with many people
releasing code. I will make any promise (short of selling my soul) that the
code will be safe and promply destroyed immediately after inspection.
Thanks for any help,
Tom
[email protected]The following describes how to establish a self many-to-many relationship with regards to Product having many parent products and many children products. I have attached the example files as well. Most of these files were generated using EJBGen. I would highly recommend it...
EJB
v Navigating from a Product to its parent Products results in getParents() method in Product
§ Since a Product can have many parents the return type of getParents() method is
java.util.Collection
§ Calling setParents() method results in establishing the new links between this Parent and
parent Products
§ Adding a Product as Parent to the Product results in establishing a new link between this
Product and other Product as parent
· This product is made available in the collection of children in the other Product
§ Removing a Product as Parent to the Product results in breaking a link between this
Product and the other Product as parent
· This product is also removed from the collection of children in the other Product
v Navigating from a Product to its children Products results in getChildren() method in Product
§ Since a Product can have many children the return type of getChildren() method is
java.util.Collection
§ Calling setChildren() method results in breaking the old links between this Product and
children Products
§ Adding a Product as child to the Product results in establishing a new link between this
Product and other Product as child
· This product is made available in the collection of parents in the other Product
§ Removing a Product as child from the Product results in breaking a link between this
Product and the other Product as child
· This Product is also removed from the collection of parents in the other Product.
v Example: ProductBean
Ø DataBase
v For a many-to-many relationship define a new associative (join) table
v Define a new Parent_Child_Product associative table
v The Parent_Child_Product has compound primary keys: Parent_Product_ID and
Child_Product_ID
v Parent_Product_ID and Child_Product_ID are foreign keys to Product table
v Example: Product, Parent_Child_Product
Ø Deployment Descriptors
v ejb-jar.xml
§ Within <ejb-jar>.<relationships>.<ejb-relation> define the following:
· Name of the relationship
o Example: <ejb-relation-name>Parent-Product-Children</ejb-relation-name>
· Role from the parent Product side
o Source
§ Example:
<relationship-role-source>
<ejb-name>Product</ejb-name>
</relationship-role-source>
o Role name
§ Example: <ejb-relationship-role-name>many-Product@children-Have-Product</
ejb-relationship-role-name>
o Multiplicity
§ Example: <multiplicity>many</multiplicity>
o CMR field
§ Example:
<cmr-field>
<cmr-field-name>children</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
· Role from the child Product side
o Source
§ Example:
<relationship-role-source>
<ejb-name>Product</ejb-name>
</relationship-role-source>
o Role name
§ Example: <ejb-relationship-role-name>many-Product@parents-Have-Product</
ejb-relationship-role-name>
o Multiplicity
§ Example: <multiplicity>many</multiplicity>
o CMR field
§ Example:
<cmr-field>
<cmr-field-name>parents</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
v weblogic-ejb-jar.xml
v weblogic-cmp-rdbms-jar.xml
§ Within <weblogic-rdbms-jar>.<weblogic-rdbms-relation> specify the following:.23
· Name of the relationship matching the name in ejb-jar
o Example: <ejb-relation-name> Parent-Product-Children</ejb-relation-name>
· Specify the name of the joint table
o Example: <table-name> Parent_Child_Product</table-name>
· Specify the mapping using <weblogic-relationship-role>
o Specify the role name matching the name in the ejb-jar
§ Example: <relationship-role-name>many-Product@children-Have-Product</
relationship-role-name>
o Define <relationship-role-map> that defines the mapping of the foreign key to
the primary key mapping
§ Example:
<relationship-role-map>
<column-map>
<foreign-key-column>Parent_Product_ID</foreign-key-column>
<key-column>Product_ID</key-column>
</column-map>
</relationship-role-map>
· Specify the mapping using <weblogic-relationship-role>
o Specify the role name matching the name in the ejb-jar
§ Example: <relationship-role-name> many-Product@parents-Have-Product</
relationship-role-name>
o Define <relationship-role-map> that defines the mapping of the foreign key to
the primary key mapping
§ Example:
<relationship-role-map>
<column-map>
<foreign-key-column>Child_Product_ID</foreign-key-column>
<key-column>Product_ID</key-column>
</column-map>
</relationship-role-map>
"Thomas A. Valletta" <[email protected]> wrote in message news:[email protected]...
I am attempting to create an EJB that uses Container Managed Persistence,
but my situation seems to be an odd one. The EJB needs to have a
Many-to-Many relationship to itself, because the object is Hierarchical.
Because this is my first EJB I am having a hard time with all of the
deployment descriptors.
I am asking for an example of any Many-to-Many EJB relationship that uses
Weblogic's built-in link table creation to make the relationship (that
works). I realize that there are confidentiality issues with many people
releasing code. I will make any promise (short of selling my soul) that the
code will be safe and promply destroyed immediately after inspection.
Thanks for any help,
Tom
[email protected]
[att1.html]
[ejb-jar.xml]
[weblogic-cmp-rdbms-jar.xml]
[weblogic-ejb-jar.xml]
[ProductBean.java]
[ProductLocal.java]
[ProductLocalHome.java] -
Idoc for CRM product and relationships
Hi,
I am looking for an IDOC for product in CRM that has also a structure representing the relationships with other products.
The transaction is COMMPR01, chose a product (of type materials), on the top of the page there is a button 'Relationships', the Accessories tab, there you can enter other products, I need an IDOC that represent this structure.
Thanks,
Naama.Hi Namma,
In crm no IDOC's are used only BDOC'S . You can look in to that angle.Like that u can get some clues.
Thanks and regards,
kumar. -
Hi,
Can anyone help me in answering my below points with repect to SNMP and EJB communication arichecture.
1) I needs to indicate clearly the EJB container containing the Fault Managment application in EJB application.
2) The relationship of EJB Container and the EJB connecter
3) The connector of EJB and its relationship to SNMP manager APIs
4) The Manager APIs to SNMP agent.
Then it should clearly say the scaling by saying that Fault Management application deployment on multiple servers the how the EJB container to SNMP agent are affected
Please reply to these queries as soon as possible
Thanks,Hi,
About the develop question please post to the MSDN forum.
MSDN forum Developer Network
http://social.msdn.microsoft.com/Forums/en-US/home?forum=WAVirtualMachinesVirtualNetwork&filter=alltypes&sort=lastpostdesc
Thanks for your understanding and support.
We
are trying to better understand customer views on social support experience, so your participation in this
interview project would be greatly appreciated if you have time.
Thanks for helping make community forums a great place.
Maybe you are looking for
-
IPad mini stopped suddenly working
Hi guys, few weeks ago I bought through the czech official apple shop iPad mini wifi 16 GB version and today I just browsed the internet and my iPad suddenly stopped working, means that black screen popped out and even if I clicked power button nothi
-
Hi, I want to know the max nof schema users that can be created in oracle 10g Standard edition. Regards Basu
-
Upload BOM Hierarchy from R/3
Hi Friends, I am new to SAP BW and require help regarding a client request of uploading R/3 BOM data into BW. The problem here is of providing multi-level BOM explosion functionality in BEx. The preferred solution for this may involve calculating
-
What features I can disable?
Hi, some of the queries in our db consumes 100% of CPU for a couple of seconds. I've got a quest to find out, which oracle features can be disabled e.g. how to simplify the Oracle to the least necessary minimum to get rid of the CPU's peaks. It's not
-
I am trying to download an app but it says it requires iOS5. I have iOS5 but it still will not load. What do I need to do?