Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Understanding CMR

Posted on 2004-09-13
6
Medium Priority
?
206 Views
Last Modified: 2010-03-31
Hi,

I've been looking for a site or a book where to learn CMR but I'm getting crazy, all the examples are too long and complicated for me to understand.

Why do I need CMR?
Well, I have two tables in my database: Tickets and Concerts. If I want to calculate the number of tickets demanded for one concert .. I suppose I need to relate Tickets and Concerts beans .. but how? What fields should I create in the tables?

I'm starting to use jBuilder and creating the relationship, once I understand what fields I have to use, is not a problem but what is a mystery to me is: after creating the fields in database and the relationship in between the beans, what's next? which is the code I have to use in the servlet in order to manage the relationship? And what about the transactions? How are they used within CMR?

Thanks a million in advance
0
Comment
Question by:Dada44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 800 total points
ID: 12042000
>> all the examples are too long and complicated for me to understand
Maybe this isn't: http://www.ideas2work.com/cmr-local.html
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12042005
0
 

Author Comment

by:Dada44
ID: 12073732
Thanks a lot. I’ve been studying the examples and I’ve created an example myself in order to apply it .. everything seems to be ok but I get an “ejb not bound” error all the time, no matter what I change.

Maybe you can help me, the example I’ve written is about to get all books from a book category (Fiction for example)
This is the jsp:


<%@page import="java.util.*,javax.transaction.*,javax.naming.*, folder.*" %>
<%
      Context ctx = new InitialContext();
      CategoryHome ch = (CategoryHome) ctx.lookup("ejb/Category");
      Category c = ch.findByPrimaryKey("Fiction");
     
      UserTransaction ut =  (UserTransaction) ctx.lookup("java:comp/UserTransaction");
      ut.begin();
      
      Collection books = c.getBook();
       %>
       
       <b>Books within the category  <%= c.getCategoryName() %></b><br>
       
         <%      Iterator it=books.iterator();
            while(it.hasNext())
            {
                  Book b=(Book)it.next();

        %>
       
<%=b.getBookName()%>

 <% }
         ut.commit();

   %>    



JBOSS.XML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">
<jboss>
  <enterprise-beans>
    <entity>
      <ejb-name>Book</ejb-name>
      <jndi-name>Folder/BookRemote</jndi-name>
      <local-jndi-name>Book</local-jndi-name>
    </entity>
    <entity>
      <ejb-name>Category</ejb-name>
      <jndi-name>ejb/Category</jndi-name>
      <local-jndi-name>Category</local-jndi-name>
    </entity>
  </enterprise-beans>
</jboss>

EJB-JAR.XML (roughly)

<ejb-jar>
  <relationships>
    <ejb-relation>
      <ejb-relation-name>book-category</ejb-relation-name>
      <ejb-relationship-role>
        <description>book</description>
        <ejb-relationship-role-name>BookRelationshipRole</ejb-relationship-role-name>
        <multiplicity>Many</multiplicity>
        <relationship-role-source>
          <description>book</description>
          <ejb-name>Book</ejb-name>
        </relationship-role-source>
        <cmr-field>
          <description>category</description>
          <cmr-field-name>category</cmr-field-name>
        </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
        <description>category</description>
        <ejb-relationship-role-name>CategoryRelationshipRole</ejb-relationship-role-name>
        <multiplicity>One</multiplicity>
        <relationship-role-source>
          <description>category</description>
          <ejb-name>Category</ejb-name>
        </relationship-role-source>
        <cmr-field>
          <description>book</description>
          <cmr-field-name>book</cmr-field-name>
          <cmr-field-type>java.util.Collection</cmr-field-type>
        </cmr-field>
      </ejb-relationship-role>
    </ejb-relation>
  </relationships>
  <assembly-descriptor>
    <container-transaction>
      <method>
        <ejb-name>Book</ejb-name>
        <method-name>*</method-name>
      </method>
      <trans-attribute>Supports</trans-attribute>
    </container-transaction>
    <container-transaction>
      <method>
        <ejb-name>Category</ejb-name>
        <method-name>*</method-name>
      </method>
      <trans-attribute>Supports</trans-attribute>
    </container-transaction>
  </assembly-descriptor>
</ejb-jar>
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12073787
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question