EJB3: One-to-one relationships and auto-generation of primary key values...

Dear Forum,
I'm relatively new to JEE, and while I've so far enjoyed the convenience of EJB3 for most things, it seems that I have a corner case that can not be handled by the entity manager.
First, here's a quick mockup of my entities:
    Gallery
            |
            -- [1] -------[1] ----> Author
            |
            -- [1] -------[M] ---> Photo
                                              |
                                              -- [1] ------ [1] -> PhotoImage
                                                                                 |
                                                                                 -- [1] ------ [1] -> IPTCData
                                                                                 |
                                                                                 -- [1] ------ [1] -> EXIFDataI also have a remote, stateless session bean that does nothing more than persist()/merge()/remove() and locate (through find() and a few custom queries) my Gallery and Photo instances.
Now, the abridged version of my problem is this: when I persist a Photo, it naturally gets its primary key generated (I used @Id and @GeneratedValue). However, for some reason none of the other dependent entities inherit Photo's primary key value. In my client, I create a new Gallery locally and then persist it. I then create new Photo, PhotoImage, IPTCData and EXIFData instances. I add the IPTCData and EXIFData instances to PhotoImage (there are PhotoImage methods for adding those); then I add the PhotoImage instance to Photo (again, Photo has a setter for adding a PhotoImage). Then, I persist the Photo.
--- Aside: ------------
I've set up my relationships using annotations like @OneToMany (Gallery references a Collection of Photos), and @OneToOne (Photo's primary key references PhotoImage's primary key; PhotoImage's primary key references the primary keys of IPTCData and EXIFData). I've also added @JoinColumn annotations where necessary.
Finally, I get the Gallery instance's Photo collection (public Collection<Photo> getPhotos()), I add the Photo to the collection, and I add the Photo collection BACK to the Gallery (public void setPhotos(Collection<Photo>)).
At this point, the Gallery should have all of my entities contained inside of itself. However, when I persist the Gallery at this point, all of the entities show up in the database, but none of the primary keys get inherited. Photo's primary key gets generated automatically, of course, but the rest have zero (0) as their PK values. I had wanted, for example, IPTCData to get the value of Photo.id.
I had assumed that the entity manager would persist everything for me provided that I told it, through my annotations, about which entities relate to which. Does persistence only work in the direction of retrieval? That is, does the entity manager only do its thing when fetching (versus setting) data when there is more than 1 object in the graph? I can't believe that it can't, otherwise we'd all be ditching it and going back to straight SQL to do our work.
Thus, I HAVE to be doing something wrong, or else omitting to do something right.
I've made other incarnations of the above setup, and none of them have worked perfectly. I've even set up foreign key constraints in the database, but I had my share of unresolvable problems there, too.
So I guess my big question with all of this is: when you have a deeply nested graph of objects, can the entity manager figure everything out and persist all of the objects correctly and with the right values? If not, boo. If so, how does one accomplish this?
I know that I could persist each and every entity separately in my client code, but I wanted to have a natural-looking way of piecing all of my entities together. More specifically, I could persist IPTCData explicitly; however, I want to be able to add everything to a Photo and only persist the Photo itself, with the idea that all of the objects and sub-objects would be persisted automagically.
Is this possible? Or have I bought into a pipe dream with the guarantee of the proverbial magic bullet?
Thanks to everyone in advance for his/her input.
Regards,
Michael

Daniel,
Late last night I found the solution to my problem. And you're right, it had everything to do with which side is wired to which. I got confused about which side to consider the "owning" side, since one can look at it from the perspective of the database or the application.
Interestingly, the first 2 lines of your example code match my client code almost verbatim: First, I create a new Gallery (or else I get an existing one). I then create a new Photo and then add it to the Gallery's collection using add(). I then persist the Gallery. My session bean internally calls EntityManager.merge(gallery). How it differs from your example, though, is in the fact that, on an application level, a Photo has no knowledge whatsoever of a Gallery. Which is to say that my Photo class does not have a 'getGallery()' method. Somehow, Hibernate is able to figure it all out and still update Photo's 'parentIdRef' column in the database. My logs show that Hibernate issues a SQL UPDATE on the Photo after both a Gallery and a Photo have been created. It sets the Photo's 'parentIdRef' column to the primary key value of the owning Gallery.
Getting back to the matter, my problem was not with being able to map a Photo to a Gallery; rather, I was unable to add a PhotoImage to a Photo and have the relationship get correctly mapped in the database. The relationship between a Photo and a Gallery is many-to-one: there can be many Photo objects inside of a Gallery. In the database, a Photo row contains a 'parentIdRef' column whose value is that of a Gallery's primary key. I used @OneToMany on the Gallery, since a Gallery is, from an application perspective, the "owning" side, even though it's only the Photo that knows who it's referring to since only IT contains the 'parentIdRef' column in the database.
I tried setting up the relationship between a PhotoImage and a Photo in the same manner, with the PhotoImage having a 'parentIdRef' column and referring to a Photo's primary key. I had annotated the Photo's getPhotoImage() method with @OneToOne, along with an appropriate @JoinColumn.
It was THIS part that I had backwards. With a @OneToMany relationship, the child refers back to the parent --- it can be no other way. However, with a @OneToOne relationship, the owner refers to the child.
So, to make a long story short, all I had to do was create extra database columns for Photo. Those columns refer to the primary keys of PhotoImage, EXIFData and IPTCData. Concretely, for example, Photo.photoImageIdRef references PhotoImage.id. And so on and so forth.
The only negative side-effect of this is that my database-level foreign key constraints are now broken, since Hibernate wants to persist PhotoImage, EXIFData and IPTCData before it persists Photo.
I have to investigate more deeply the 'cascade=...' option of the @OneToOne annotation in order to find out it relates, if at all, to a database-level cascade.
Anyway, thanks for the reply. It seems that you had a very good idea about what my problem was. I would have posted the fact that I had resolved the problem last night, except that it was too late and I was heading to bed. If you still want the Duke points, let me know. I don't currently know the rules about if, when and to whom I should issue points in cases like these when I've already solved the problem.
Regards,
Michael

Similar Messages

  • How to get the auto increment integer primary key value of a new record

    I have a DB table that has a auto increment integer primary key, if I insert a new record into it by SQL statement "INSERT INTO...", how can I get the integer primary key value of that newly created record?

    Well maybe someone knows a better method, but one workaround would be to add a dummy field to your table. When a new record is inserted this dummy field will be null. Then you can select your record with SELECT keyField FROM yourTable WHERE dummyField IS NULL. Once you've got the key number, you then update the record with a non-null value in the dummyField. Bit of a bodge, but it should work...
    Another alternative is, instead of using an Autonumbered key field, you could assign your own number by getting the MAX value of the existing keys (with SELECT MAX(keyField) FROM yourTable) and using that number + 1 for your new key. Might be a problem if you have lots of records and frequent deletions though.

  • Auto Increment of primary key value in jdeveloper.

    hi all,
    i have one table with one primary key.
    i want to increment that primary key when ever i go for CreateInsert or create operation in JSF page.
    i have tried with db sequence value type, but i was not able to achieve my condition. in DB Sequence i got error like cannot convert java.class.string to java.class.dbsequence.
    can any one suggest me in this to achieve my condition.
    regards,
    M vijayalakshmi.

    hi all,
    from this i found the simple method to achive the auto increment of primary key.
    http://www.techartifact.com/blogs/2012/10/adding-number-for-primary-key-in-oracle-adf-using-groovy-by-sequence.html#ixzz2EeU9CWo6
    in this am facing an one small issue.
    intial value of the primary key is 1.
    for this value i have entered the row of data.
    again i have clicked on the create button.
    then the value of the primary key has increased to 2.
    for this value i didnt entered the row of data to databse.
    just i closed the browser.
    if i run the run page again, the value of primary key is 3.
    my requirment is i shd get the value of primary key is "2".
    the increment shd happen the maxi value present in the primary key of the table.
    can any one help me in this how to achive this.
    thanks in advance.
    regards,
    M vijayalakshmi.

  • APEX 4.0 -Show and able to change Primary key values for Detail

    In a Master-Detail form, is there anyway I can show and able to change/select my primary keys from a select list field? One of my primary keys on the Detail is also primary key from another table which restricts my values for this field. I was able to show the fields but I can not make changes to this field and save the changes. Is there anyway I can have both show the field and able to change field's value and save it? Please advice. Thank you very much for your help in advance.
    -Grace

    Yes AFAIK Apex (for better or worse) was designed such that the PKs are generated automatically with PL/SQL, by a trigger, or whatever other algorithm that isn't in the control of the end user. It also only seems to allow a composite PK of no more than two columns.
    My usual strategy is to:
    1. Define the PK as a number (some sort of RECORD_ID, RECORD_SEQ, whatever) and populate it via a trigger on-insert.
    2. Define the "business" PK as a separate unique index. This way the user can set and modify it to their heart's content and it also isn't limited to just two columns (if the composite key's business requirement is such that more than two columns are needed).

  • Auto generate the primary key value for eah valid insertion

    i have a table EMP having emp_id, name and age.
    EMP;
    E1 John 23
    E2 Mary 25
    created a form/report page on the table. the report page displays all the columns. while creating new entry, the emp_is hidden and the name , age are displayed. on successful insertion the emp_id is populated with 1 rather then E3.
    1 Rick 22
    E1 John 23
    E2 Mary 25
    how do i ensure that the new row inserted has a value E3 and the subsequent entries, emp_id is incremented by next sequence.

    If your emp_id is not numeric and needs to be 'E' + sequence then you need to delete the existing trigger and create a new one like this:
    CREATE OR REPLACE TRIGGER emp_bi_trg
       BEFORE INSERT
       ON emp
       FOR EACH ROW
    BEGIN
       IF :NEW.emp_id IS NULL
       THEN
          SELECT 'E' || emp_seq.NEXTVAL
            INTO :NEW.emp_id
            FROM DUAL;
       END IF;
    END;
    /Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    ------------------------------------------------------------------------------

  • About Automatic generation of Primary key

    I have created one Z table. Its composite primary keys are vkorg
    and Sales Representive Number. I have to assign Sales Representive number
    through system. How it should be done?
    Message was edited by:
            Nilesh Vakil

    Nilesh , You asked the Same question in ABAP General
    Please Refer the link.
    Re: About Automatic Generation of Primary key
    Regards
    Rusidar S
    Message was edited by:
            Rusidar Subramani

  • Display the second report as modalform and filter with primary key value of first report when you click on first report column link

    Hi All,
    I have two reports.
    1. order report
    2. order detail report
    when you click on the order report column it display the order detail report as a modal form.
    i was done below steps.
    1. In page header i was written the below code
    <link rel="stylesheet" href = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/
    redmond/jquery-ui.css" type="text/css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"> </script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"> </script>
    <script type="text/javascript">
    $( function() {
    $('#ModalForm1').dialog(
    autoOpen : false ,
    width :470,
    height: 500,
    resize :false,
    function openForm1()
    $('#ModalForm1').dialog('open');
    function closeForm()
    $('#ModalForm1 input[type="text"]').val('');
    $('#ModalForm1').dialog('close');
    </script>
    2. order report.
    3. order detail report
       select * from order_details where order_id = p_order_id;
    region header
    <div id="ModalForm1" title="Ordered Items" style="display:none">
    <p class="msg"></p>
    footer
    </div>
    4. created the hidden item in order detail report.
    5. in order report column attributes i was given link like below.
    javascript:$s('p_order_id','#order_id#');openForm1();
    when i click on the order report column link it passing the row primary key value to hiddent and open the report as modal form. however it is not filter the report with hidden item. it showing the no data found.
    problem is hidden item value is not submitting. once we submit that value it showing the 2nd report with filter data.
    can any help me to achieve above requirement.
    apex: 4.2
    oracle 11g
    Regards,
    Vijay.

    Vijay,
    Issue 1: Your usage of $s() JavaScript API seems to be wrong. For the first parameter, you need to use the name of the hidden page item and not p_order_id.
    javascript:$s('P1_ORDER_ID','#ORDER_ID#');openForm1();
    Issue 2: Seems like you are not setting the hidden page item's value in session state. Assuming your hidden page item is called P1_ORDER_ID, Under "Region Definition" tab of your "Order Detail Report" under "Source" tab, for page items to submit, enter the name of the hidden page item P1_ORDER_ID.
    Thanks!
    JMcG

  • Hi All,How2 delete a pkey for std table and add 2 new primary keys

    Hi All,
            How2 delete a pkey for std table and add 2 new primary key fields .Please provide me the required procedure .
    Thanks&Regards.
    Bharat.

    Hi Bharat,
    First thing is you need to have the access key to change any standard dictionary object/standard programs/ standard transactions.You may get this from your basis person after getting approval from your respective manager.But changing or modifying the standard object is not recommended, but if there is no alternate to meet the business requirement then we have to follow this way only.
    Next, you need to check whether this table's primary key is being used in any other table as foreing key or not. If there is, then you must remove this relation and then you can delete the unncessary primary key field from that table.Finally you can add the two new fields and set them as primary key, save, check for any errors and activate.
    Hope this helps.
    Please reward if useful.
    Thanks,
    Srinivasa

  • JPA one to many relationship and serialization

    Hi,
    I modeled a one to may relationship like this:
    Parent Class WFData:
    @OneToMany(mappedBy = "wfData", targetEntity = Positionen.class)
    private Set<Positionen> positionen;
    Child Class Positionen
    @ManyToOne
    @JoinColumn(name = "WF_REF_ID", referencedColumnName = "ID")
    private WFData wfData;
    Now I want to create an EJB session bean with a method which returns an object of type WFData (parent) published as web service . When I try to deploy the web service I get the following error message: Unable to generate serialization framework for web service
    Does anyone know how to serialize a one-to-many relationship so I can use these objects in a web service?
    Best regards,
    Kevin

    I found the solution to get serialization correctly working and enable the service to be used in Visual Composer.
    You need to add the tag @XmlTransient to the getter method of the attribute in the child class that references the parent.
    @XmlTransient
    public WFData getWfData() {
        return wfData;

  • Column prefix and automatic generation of surrogate key

    Hello,
    I used Oracle Designer and could always generate columns with prefixes and got surragate keys as Primary key. Now I cannot find these properties in data modeler.
    Thank you for your help
    Siegwin

    Hello Siegwin,
    Abbreviation (Abkurzung) is on the General (Allgemein) tab in the Properties Dialog for a Table in the Relational Model.
    There are 2 alternative ways to run the Transformation script:
    1.  Right_click on the Relational Model in the Browser, and select Apply Custom Transformation Scripts (Benutzerdefinierte Transformationsskripte anwenden) from the drop-down menu.
        Use the right arrow to move "Table abbreviation to column" from the left column into the right column.
        Select the Apply (Anwenden) button.
    Alternatively
    2.  From the Tools (Extras) menu select Design Rules/Transformations (Entwurfsregeln/Transformationen).
        Select the fourth entry ("Table abbreviation to column") and click the Apply (Anwenden) button.
        Then click the Close (Schliessen) button.
    Note that you can run Data Modeler in English if you wish.
    First close Data Modeler and then edit the file datamodeler.conf (if you are using Data Modeler in 32 bit mode) or datamodeler64.conf (if you are using Data Modeler in 64 bit mode).
    These files are in folder datamodeler\datamodeler\bin.
    To run Data Modeler in English, you should add the following lines to the file:
    AddVMOption -Duser.country=US
    AddVMOption -Duser.language=en
    Regards,
    David

  • Ability to auto create a primary key column while creating an entity ?

    Product : oracle data modeler ( 3.0.0.665 32 bit version ) on windows XP Professional , : Target DB Oracle 11GR2
    I am new to Mozilla Rhino. Is it feasible to have a mechanism where in the primary key column name would be auto generated when the entity ( name ) is just created for the first time, and it has no columns defined yet . For e.g. one could create an entity named vendor , and after the table name is typed in, a column vendor identifier,of type numeric , is to be auto created. This mechanism should work even if the entity name changes, and the primary key is in format {tablename}_id , but it should not , if the primary key was manually set in later and is not in the expected format.

    I created this script (1) for adding an ID column (using a specific domain) to all supertype entities that do not already have an ID attribute, and a script (2) for adding primary key constraints to all ID attributes.
    - Marc de Oliveira
    Script 1:
    entities = model.getEntitySet().toArray();
    domain = model.getDesign().getDomainSet().getByName('Integer DIS Domain');
    for (var e = 0; e<entities.length;e++)
    entity = entities[e];
    if (entity.getHierarchicalParent()==null)
    attributes = entity.getAttributes().toArray(); // find existing attributes
    IDattribute = null;
    for (var a = 0; a<attributes.length; a++) // look for an ID attribute
    if (attributes[a].getName()=="ID") { IDattribute = attributes[a]; }
    if (IDattribute==null) // if an ID attribute was not found...
    IDattribute = entity.createAttribute(); // create a new ID attribute
    IDattribute.setName("ID");
    IDattribute.setDomain(domain);
    entity.moveToIndex(IDattribute,0); // move ID attribute to top
    Script 2:
    entities = model.getEntitySet().toArray();
    for (var e = 0; e<entities.length;e++)
    entity = entities[e];
    attributes = entity.getAttributes().toArray(); // find existing attributes
    IDattribute = null;
    for (var a = 0; a<attributes.length; a++) // look for an ID attribute
    if (attributes[a].getName()=="ID") { IDattribute = attributes[a];}
    if (IDattribute!=null) // if an ID attribute was found...
    key = entity.createCandidateKey(); // Create a key
    key.add(IDattribute); // Add the ID attribute to the key
    key.setPK(true); // Define the key as a primary key
    PKName = entity.getName().replace(" ","_")+"_PK";
    key.setName(PKName); // Define the key as a primary key
    entity.setPK(key); // workaround for bug...
    }

  • Problem with JPA Implementations and SQL BIGINT in primary keys

    I have a general Question about the mapping of the SQL datatype BIGINT. I discovered, that there are some different behaviour depending on the JPA implementation. I tested with TopLink Essentials (working) and with Hibernate (not working).
    Here is the case:
    Table definition:
    /*==============================================================*/
    /* Table: CmdQueueIn */
    /*==============================================================*/
    create table MTRACKER.CmdQueueIn
    CmdQueueInId bigint not null global autoincrement,
    Type int,
    Cmd varchar(2048),
    CmdState int,
    MLUser bigint not null,
    ExecutionTime timestamp,
    FinishTime timestamp,
    ExecutionServer varchar(64),
    ScheduleString varchar(64),
    RetryCount int,
    ResultMessage varchar(256),
    RecordState int not null default 1,
    CDate timestamp not null default current timestamp,
    MDate timestamp not null default current timestamp,
    constraint PK_CMDQUEUEIN primary key (CmdQueueInId)
    The java class for this table has the following annotation for the primary key field:
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "CmdQueueInId", nullable = false)
    private BigInteger cmdQueueInId;
    When using hibernate 3.2.1 as JPA provider I get the following exception:
    avax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: this id generator generates long, integer, short or string
    at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
    at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:218)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:176)
    at $Proxy16.persist(Unknown Source)
    at com.trixpert.dao.CmdQueueInDAO.save(CmdQueueInDAO.java:46)
    at com.trixpert.test.dao.CmdQueueInDAOTest.testCreateNewCmd(CmdQueueInDAOTest.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at junit.framework.TestCase.runTest(TestCase.java:154)
    at junit.framework.TestCase.runBare(TestCase.java:127)
    at
    Caused by: org.hibernate.id.IdentifierGenerationException: this id generator generates long, integer, short or string
    at org.hibernate.id.IdentifierGeneratorFactory.get(IdentifierGeneratorFactory.java:59)
    at org.hibernate.id.IdentifierGeneratorFactory.getGeneratedIdentity(IdentifierGeneratorFactory.java:35)
    at org.hibernate.id.IdentityGenerator$BasicDelegate.getResult(IdentityGenerator.java:157)
    at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:57)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2108)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2588)
    at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
    at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
    at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
    at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
    at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
    at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
    at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
    at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
    at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
    at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:212)
    ... 34 more
    This means, that their ID generator does not support java.math.BigInteger as datatype.
    But the code works if I take TopLink essentials as JPA Provider.
    Looking at the spec shows the following:
    In chapter 2.1.4 "If generated primary keys are used, only integral types will be portable." Integral datatypes are byte, short, int, long and char. This would mean, that the Hibernate implementation fits the spec but there seem to be a problem in general with BIGINT datatypes.
    I use a SYBASE database. There it is possible to declare a UNSIGNED BIGINT. The range of numbers is therefore 0 - 2^64 - 1. Since in Java a long is always signed it would mean its range is from -2^63 -1 to 2^63 -1. So a mapping of BIGINT to java.lang.long could result in an overflow.
    The interesting thing is, that I used NetBeans to reverse engineer an existing database schema. It generated for all Primary Keys of Type BIGINT automatically a java.math.BigInteger. But for other fields (not being keys) it mapped BIGINTs to java.lang.long.
    It looks like there are some problems with either the spec itself or the implementation of it. While TopLink seems to handle the problem correctly, Hibernate doesn't. But Hibernate seems to fulfill the spec.
    Is anybody familiar with the Spec reading this and can elaborate a little about this situation?
    Many thanks for your input and feedback.
    Tom

    Not sure if I clearly understand your issue, would be good if you can explain it a bit more clearly.
    "I select a value from LOV and this value don't refresh in the view"
    If you mean ViewObject, check if autoSubmit property is set to true.
    Amit

  • Using attachments in work-flow and creating custom text with key values

    Hi,
    I have 2 simple requirements.
    1. how to attach a tcode or trigger method of business object for work-flow item. The user should be able to navigate to transaction to see data before approval or rejection.
    2. I have created custom task for long text that will be displayed in the SAP inbox. How do I provide key values in this long text.  I was able to do in the subject line using Substitution parameters(&Name1& etc..)
    Regards
    Kasi

    I did the same thing. see details.
    Created Workitem and attached a task "TS92500097". in the task, I mentioned Business Object and method to be called. I have set the binding also for this business object. the method I am calling is nothing but just "display" which is using call transaction.  2 problems here.
    1. How do I show  this "BusinessObject.Display" as an attachment or link in the mail.
    2. how do I assign key values during exection of this attachment or link.
    Regards
    Kasi
    2.

  • One to many mappings and combination generation

    Please help folks,
    I want to perform one to many mapping i.e a single row of data will be taken from a single table Table 'A' into Hashtable A and it has to be matched with 'n' number of rows from another table Table 'B' taken into Hashtable B. The no. of rows selected from B can be 1/2.... upto n. For performing this mapping iam using a Combination Generator Code which will Key nos. to be selected for checking whether they can be mapped and then further processing is done on these key nos. returned by the combination generator. The code for combination generator is given below.
    The issue is say if there are about 50 rows in table B then no of combinations possible are 2 ^ 50, which is just too much for the PC to handle i.e the code takes about 4-5 days of processing time. 256 MB RAM, P4. The mapping has to be done in 30 minutes!!!! Ne ideas folks????
    // Systematically generate combinations.
    import java.math.BigInteger;
    public class CombinationGenerator {
    private int[] a;
    private int n;
    private int r;
    private BigInteger numLeft;
    private BigInteger total;
    // Constructor
    public static void main(String[] args)
    String[] elements = {"a", "b", "c", "d", "e", "f", "g"};
    int[] indices;
    CombinationGenerator x = new CombinationGenerator (elements.length, 3);
    StringBuffer combination;
    while (x.hasMore ()) {
    combination = new StringBuffer ();
    indices = x.getNext ();
    for (int i = 0; i < indices.length; i++) {
    combination.append (elements[indices[i]]);
    System.out.println (combination.toString ());
    public CombinationGenerator (int n, int r) {
    if (r > n) {
    throw new IllegalArgumentException ();
    if (n < 1) {
    throw new IllegalArgumentException ();
    this.n = n;
    this.r = r;
    a = new int[r];
    BigInteger nFact = getFactorial (n);
    BigInteger rFact = getFactorial (r);
    BigInteger nminusrFact = getFactorial (n - r);
    total = nFact.divide (rFact.multiply (nminusrFact));
    reset ();
    // Reset
    public void reset () {
    for (int i = 0; i < a.length; i++) {
    a[i] = i;
    numLeft = new BigInteger (total.toString ());
    // Return number of combinations not yet generated
    public BigInteger getNumLeft () {
    return numLeft;
    // Are there more combinations?
    public boolean hasMore () {
    return numLeft.compareTo (BigInteger.ZERO) == 1;
    // Return total number of combinations
    public BigInteger getTotal () {
    return total;
    // Compute factorial
    private static BigInteger getFactorial (int n) {
    BigInteger fact = BigInteger.ONE;
    for (int i = n; i > 1; i--) {
    fact = fact.multiply (new BigInteger (Integer.toString (i)));
    return fact;
    // Generate next combination (algorithm from Rosen p. 286)
    public int[] getNext () {
    if (numLeft.equals (total)) {
    numLeft = numLeft.subtract (BigInteger.ONE);
    return a;
    int i = r - 1;
    while (a[i] == n - r + i) {
    i--;
    System.out.println("inside while");
    a[i] = a[i] + 1;
    for (int j = i + 1; j < r; j++) {
    a[j] = a[i] + j - i;
    numLeft = numLeft.subtract (BigInteger.ONE);
    return a;

    Next time you post, see the formatting guidelines [url http://forum.java.sun.com/features.jsp#Formatting]here. //--------------------------------------
    // Systematically generate combinations.
    import java.math.BigInteger;
    public class CombinationGenerator {
    private int[] a;
    private int n;
    private int r;
    private BigInteger numLeft;
    private BigInteger total;
    // Constructor
    public static void main(String[] args)
    String[] elements = {"a", "b", "c", "d", "e", "f", "g"};
    int[] indices;
    CombinationGenerator x = new CombinationGenerator (elements.length, 3);
    StringBuffer combination;
    while (x.hasMore ()) {
    combination = new StringBuffer ();
    indices = x.getNext ();
    for (int i = 0; i < indices.length; i++) {
    combination.append (elements[indices]);
    System.out.println (combination.toString ());
    public CombinationGenerator (int n, int r) {
    if (r > n) {
    throw new IllegalArgumentException ();
    if (n < 1) {
    throw new IllegalArgumentException ();
    this.n = n;
    this.r = r;
    a = new int[r];
    BigInteger nFact = getFactorial (n);
    BigInteger rFact = getFactorial (r);
    BigInteger nminusrFact = getFactorial (n - r);
    total = nFact.divide (rFact.multiply (nminusrFact));
    reset ();
    // Reset
    public void reset () {
    for (int i = 0; i < a.length; i++) {
    a = i;
    numLeft = new BigInteger (total.toString ());
    // Return number of combinations not yet generated
    public BigInteger getNumLeft () {
    return numLeft;
    // Are there more combinations?
    public boolean hasMore () {
    return numLeft.compareTo (BigInteger.ZERO) == 1;
    // Return total number of combinations
    public BigInteger getTotal () {
    return total;
    // Compute factorial
    private static BigInteger getFactorial (int n) {
    BigInteger fact = BigInteger.ONE;
    for (int i = n; i > 1; i--) {
    fact = fact.multiply (new BigInteger (Integer.toString (i)));
    return fact;
    // Generate next combination (algorithm from Rosen p. 286)
    public int[] getNext () {
    if (numLeft.equals (total)) {
    numLeft = numLeft.subtract (BigInteger.ONE);
    return a;
    int i = r - 1;
    while (a == n - r + i) {
    i--;
    System.out.println("inside while");
    a = a + 1;
    for (int j = i + 1; j < r; j++) {
    a[j] = a + j - i;
    numLeft = numLeft.subtract (BigInteger.ONE);
    return a;
    }

  • To get a row of value by taking table name and primary key value

    i can't find out what's wrong.. pliz help.. m a fresher in SAP.
    code is here
    PARAMETER tname(10) TYPE c.
    PARAMETER pkv(10) TYPE c.
    DATA:
    lt_dd03l TYPE STANDARD TABLE OF dd03l,
    ls_dd03l TYPE dd03l.
    DATA: my_table TYPE REF TO data,
    wa_ref TYPE REF TO data.
    FIELD-SYMBOLS: <it_tname> TYPE STANDARD TABLE,
      <tname_wa> TYPE ANY,
       <primary_key> TYPE ANY,
      <is_tname>.
    SELECT * FROM dd03l INTO TABLE lt_dd03l
                 WHERE tabname EQ tname.
    LOOP AT lt_dd03l INTO ls_dd03l.
      IF ls_dd03l-fieldname NE 'MANDT' AND ls_dd03l-keyflag = 'X'.
    WRITE:/ ls_dd03l-fieldname.
       primary_key = ls_dd03l-fieldname.
        EXIT.
      ENDIF.
    ENDLOOP.
    CREATE DATA my_table TYPE STANDARD TABLE OF (tname).
    ASSIGN my_table->* TO <it_tname>.
    CREATE DATA wa_ref LIKE LINE OF <it_tname>.
    ASSIGN wa_ref->* TO <tname_wa>.
    WRITE: / ls_dd03l-fieldname.
    ASSIGN ls_dd03l-fieldname TO <primary_key>.
    SELECT * INTO TABLE <it_tname>  FROM (tname)
    WHERE <primary_key> =  pkv.
    WRITE sy-subrc.
    *WRITE : /   primary_key,
    kv .
    LOOP AT <it_tname> INTO <tname_wa> .
      DO.
        ASSIGN COMPONENT  sy-index
                 OF STRUCTURE <tname_wa> TO <is_tname>.
       WRITE:/ <is_tname>-(primary_key).
        IF sy-subrc <> 0.
          WRITE :/ 'sy-subrc is not zero'.
          EXIT.
        ENDIF.
    IF ls_dd03l-fieldname = pkv.
        WRITE: <is_tname>.
    ENDIF.
      ENDDO.
    ENDLOOP.
    *ASSIGN <t_itab> TO <t_isturct>.
    *SELECT * FROM (tname) INTO TABLE <t_itab>.
    *LOOP AT <t_itab> INTO <t_isturct>.
    WRITE :/
      <t_isturct>.
    *ENDLOOP.

    Please check whether bname has any conversion exits.
    try hardcoding the value like '0000105397' and passing into the query.
    SELECT * FROM (tname) INTO table <it_tname>
    where <primary_key> = '0000105397'.  "If it works then use conversion exit.
    or try like this
    types : begin of ty_where,
            line type char100,
            end of ty_where.
    data:it_where type table of ty_where.
    data:wa_where type ty_where.
    data:val type char100.
    concatenate <primary_key> 'EQ' into wa_where-line seperated by space.
    concatenate `'` pkv `'` into val. condense val no-gaps.
    concatenate wa_where-line val into wa_where-line seperated by space.
    append wa_where to it_where.
    SELECT * FROM (tname) INTO table <it_tname>
    where ( it_where ).

Maybe you are looking for

  • Computer freeze problem

    hi, I got a problem with my Macbook Pro Mid 2010 model. it some times freezes with a scratching sound or some very loud beeps and here is the kernel fault report for today: panic(cpu 3 caller 0xffffff80074dc19e): Kernel trap at 0xffffff800749f6c4, ty

  • Can't Import MP4 Files Into DVD Studio Pro

    I'm trying to start a DVD Studio Pro 4 project, and have .mp4 video files. When I import them with the Assets>Import tab, they come in as MP4 audio files only, not movie files. The users manual says the integrated encouder auto encodes Quick Time ass

  • Widget accordion states are not changing.

    Widget accordion states can not be altered individually. HELP!

  • How can I force the close of a third party ActiveX server.

    We have a third party ActiveX executable that refuses to shut itself down once in a while. And when I say once in a while, I mean one out of every 20-30 times it's attempted. All termination commands are being sent and recieved properly, and all refn

  • Window mobile 6

    Can the iPhone handle email from Windows Mobile 6?