JAI + JAI Image IO - ImageWrite operation problem: color reversed

I installed jai 1.1.3 and jai imageio 1.1 on jdk 1.6 and did a test with the following code.
     public static void main(String args[]) {
          Byte[] bandValues = new Byte[3];
          bandValues[0] = (byte)255;
          bandValues[1] = (byte)0;
          bandValues[2] = (byte)0;
          ParameterBlock params = new ParameterBlock();
          params.add((float)300).add((float)200);
          params.add(bandValues);
          PlanarImage bim = JAI.create("constant", params);
          JAI.create("imagewrite", bim, "d:/dev/baseImage.png", "PNG");
          JAI.create("filestore", bim, "d:/dev/baseImage2.png", "PNG");
          PlanarImage pi = JAI.create("imageread", "d:/dev/baseImage.png");
          PlanarImage pi2 = JAI.create("imageread", "d:/dev/baseImage2.png");
          JFrame frame = new JFrame();
          frame.setTitle("Output Image");
          Container contentPane = frame.getContentPane();
          contentPane.setLayout(new GridLayout(1,3));
          contentPane.add(new JScrollPane(new DisplayJAI(bim)));
          contentPane.add(new JScrollPane(new DisplayJAI(pi)));
          contentPane.add(new JScrollPane(new DisplayJAI(pi2)));
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(960, 400);
          frame.setVisible(true);
     }I found that the color in the output file created by "imagewrite" was reversed - bim is red but pi is blue.
The one created by "filestore" was correct: pi2 was red.
Did I use the "imagewrite" operation incorrectly? How should I use the imagewrite operation?

I think you are using it correctly and you've encountered a bug. The same thing occurs on my machine. PlanarImage is using an interlaced raster which stores pixels as BGRBGRBGR ect... But the only way I can see this causing a problem is if the imagewrite operation was going directly to the DataBuffer for the pixels. If it retrieved it through the raster the colors should not be switched.
Interestingly enough if I do this
JAI.create("imagewrite", bim.getAsBufferedImage(), "d:/dev/baseImage.png", "PNG");then it works correctly. This suggests even more that the fault is with imagewrite operation interpreting the PlanarImage wrongly.

Similar Messages

  • JAI export of images on laptop have wrong colors

    Has anyone come across a problem where the exportation of image formats (jpeg, png) from JAI end up with almost negated colors that the original? I have an application that draws to the Graphics of an Image object, and I successfully export that AWTImage using techniques found here in the forums. My PC works great but my laptop ends up with a dark green instead of white background in the saved file.
    Here is the code I use to convert a java.awt.Image to a PNG file:
    public void exportPNG(Image image)
      if (image == null)
        return;
      try
        JFileChooser chooser = new JFileChooser();
        if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
          this.repaint();
          this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
          String filename = chooser.getSelectedFile().getCanonicalPath();
          OutputStream output = new BufferedOutputStream(new FileOutputStream(filename));
          ParameterBlock pb = new ParameterBlock();
          pb.addSource(image);
          pb.add(DataBuffer.TYPE_BYTE);
          PNGEncodeParam.RGB encodeParam = new PNGEncodeParam.RGB();
          ImageEncoder encode = ImageCodec.createImageEncoder("PNG", output, encodeParam);
          encode.encode(JAI.create("format", pb));
          output.close();
          } // ends if
        else
          JOptionPane.showMessageDialog(this, "Image export cancelled", "Cancel", JOptionPane.INFORMATION_MESSAGE);
        } // ends try
      catch(Exception e)
        String message = "Could not export the image because of the error:\n " + e.getMessage();
        JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.WARNING_MESSAGE);
        } // ends catch(Exception)
      finally
        this.repaint();
        this.setCursor(Cursor.getDefaultCursor());
        } // ends finally
      } // ends exportPNG(Image)
    Does anyone have any ideas?

    I heard back from a Sun staffer and apparently I was using the JAI code incorrectly. The oddity is that I was getting a legitimate result on all non-Windows 2000 machines. Here's the distinction if anyone else has this issue.
    // This commented block causes image corruption on Windows 2000 machines.
    // The corrected version can be found below.
    // ParameterBlock pb = new ParameterBlock();
    // pb.addSource(image);
    // pb.add(DataBuffer.TYPE_BYTE);
    ParameterBlock pb = new ParameterBlock();
    pb.add(image);
    PlanarImage imgSrc = JAI.create("awtImage", pb);
    pb = new ParameterBlock();
    pb.addSource(imgSrc);
    pb.add(DataBuffer.TYPE_BYTE);
    The rest should be as above in the original posting.

  • Converting awt to JAI image - please help!

    My application needs to be able to create a JAI image and apply dither to it.
    I got this working by using the fileload operator in JAI to load the image and convert it to a planar image but when I try to use the awtImage operator to convert the images to planar images it doesn't work.
    I really don't understand why this is. The two methods are pratically identical.
    This is the method that works and the error diffusion method
    public void setDitherOp(String op, String picName,KernelJAI typeDither)
                          //operation name, parameter block
        srcImg = JAI.create("fileload", "Pics/"+picName);
        dataType = srcImg.getSampleModel().getDataType();
                  //contains parameters to be used in dither operation
        pb = new ParameterBlock();
        pb.addSource(srcImg);
        layout = new ImageLayout();
        if(op=="ordered")
          orderedDither();
        else if(op=="error")
          errorDiffDither(typeDither);
    public void errorDiffDither(KernelJAI typeDither)
          if(srcImg.getNumBands()==1)   //source image has one color band
            LookupTableJAI lut =new LookupTableJAI(new byte[] {(byte)0x00, (byte)0xff});
            pb.add(lut);
            pb.add(typeDither);
            byte[] map = new byte[] {(byte)0x00, (byte)0xff};
            ColorModel cm = new IndexColorModel(1, 2, map, map, map);
            layout.setColorModel(cm);
          else if(srcImg.getNumBands()==3)  //source image has three color bands
            pb.add(ColorCube.BYTE_496);  //add color cube to parameter block
            pb.add(typeDither);          //add error filter kernel
            System.out.println("error diffusion num bands is: "+srcImg.getNumBands());
          RenderingHints rhints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);
          ditheredImage = JAI.create("errordiffusion", pb, rhints);
          if(ditheredImage==null)System.out.println("Dithered image is NULL");
    This is the one that doesn't!
    public void setDitherOp(String op, Image frameImage,KernelJAI typeDither)
        srcImg = JAI.create("AWTImage", frameImage);
        dataType = srcImg.getSampleModel().getDataType();
                  //contains parameters to be used in dither operation
        pb = new ParameterBlock();
        pb.addSource(srcImg);
        if(srcImg==null)System.out.println("src image null in set dither op");
        /*if(srcImg!=null)
            ditheredImage = JAI.create("Invert", pb);
        layout = new ImageLayout();
        if(op=="ordered")
          orderedDither();
        else if(op=="error")
          errorDiffDither(typeDither);
    public PlanarImage getDitheredImage()
        return ditheredImage;
      }The other really odd thing in the method that uses the awtImage operator is this:
    if the code to invert the colours is executed it works fine. This must mean that it is creating the planar image from the awt image? I really don't see what the problem could be in that case because it uses the same error diffusion method after that.
    Please help me with this - its part of a project thats due up in a few days and I really need to get this part working as soon as possible.
    CurtinR

    Hi morgair,
    Thank you so much for answering!!
    You're right - the FileLoad and awtImage operators return different types of objects.
    FileLoad returns a RenderedImage
    JAI.create("fileload", "Pics/"+picName);awtImage returns a PlanarImage. The sample model and color model are set according to the AWT image data.
    srcImg = (PlanarImage)JAI.create("AWTImage", pbAwtOp);Also the error diffusion operation takes a renderedImage as a parameter. It says in the programming guide that the source image and the color map must have the same data type and number of bands. (That would explain why the method using fileLoad worked!)
    How do I change the Planar image to a rendered imaage or specify the sample model and colour model of srcImg. I've been trying to do this but am going round in circles - there are descrepancies between the programmers guide and the API and I'm lost..
    Any suggestions really really appreciated..

  • On my screen the image is clear and the colors are right, However when I print to either my epson of HP the image color is off.

    On my Mac screen my photo image is clear and the color are right, however when I print to either my epson 2200 or my HP printer bother the colors are off and the image is not as clear as on the screen.

    Hi there,
    This article should cover the issue you are experiencing. Give the steps outlined a shot and let us know if it helps.
    Best of Luck!
    You can say thanks by clicking the Kudos Star in my post. If my post resolves your problem, please mark it as Accepted Solution so others can benefit too.

  • Because I have taken over 9,999  pics, my phone is now duplicating image numbers. The problem is when I am importing with Image Capture, when I select images, the program is importing BOTH the old images of the same number as well as the new ones. Help?

    Because I have taken over 9,999 images, my phone is now duplicating image numbers. The problem is that Image Capture now imports BOTH images when I select the new ones that share numbers with old ones.  The images were completely mixed when they showed up in Image Capture - Old image 0001, new image 0001, old image 0002, new image 0002 and so forth. I clicked on "date," which then rearraged the images, and I selected only the new ones, but when they actually import to my computer BOTH old and new images are importing. Has anyone figured out how to solve this problem?

    Well, obviously all I needed to do  to solve the problem was to post about it. It has stopped, so all is well!

  • IPhone 5 pixelated images in various apps problem- occurred within last 2 months and must be a result of apple network driver update

    iPhone 5 pixelated images in various apps problem- occurred within last 2 months and must be a result of apple network driver update
    What's the fix?
    Tried reset, restart, reboot, reopen of apps same problem

    What do you mean by reboot? Do you mean restore? Because if you haven't restored, then that's the next step. You'll need a computer with the latest version of iTunes and a USB connector.
    For Mac:
    http://support.apple.com/kb/PH12124
    For PC:
    http://support.apple.com/kb/PH12324

  • For the last 2 days whenever I try to upload photos from my iPhoto page to facebook I get an error message: Bad Image There was a problem with the image file.  I haven't knowingly changed any settings on iPhoto or facebook. Can anyone help, please ?

    I need help with uploading photos from iPhoto to facebook. I could do it till 2 days ago. Now any new photo I try to upload gives me an error message:
    Bad Image
    There was a problem with the image file. 
    Please help.

    Can you drag it to the Desktop?

  • Images are color-reversed i.e. "negative image"

    Opened an existing file in pages that has jpeg images in it. They are reversed.
    I pasted a new image into it. It is also reversed. In others words, mostly just a black square, but you can see the originally-dark areas as light areas.
    A few months ago I upgraded my OS to Tiger.
    thanks for any help.

    If the image contains a color profiile, it's used.
    Correct.
    If not, a generic color profile is used that is appropriate for the file in some way.
    Correct.
    If you place a photograph with RGB image data, whether the file format is TIFF, JPEG, or PNG, and if there is no ICC profile in the image, the system automatically assigns the Generic RGB Profile.
    In OS X 10.5 and lower this is for gamma 1.8 and 6500 Kelvin with Sony Trinitron phosphors. In OS X 10.6 and higher this is sRGB for a higher gamma and a paler, less punchy appearance.
    When I don't embed the suggested color profile when saving from Photoshop, the colors are a little off when printing
    Photoshop version 6 and higher has the ability to assign a source ICC profile while the image data is in Photoshop's memory and is shown in the ColorWorld configured for Photoshop window, but not to include that ICC soruce profile when the image data is saved to disk.
    The following application then has to assume a source ICC profile and assign that when configuring a ColourWorld, the principle of thing being that a colour matching session, called a ColorWorld, has to have an ICC source, one or more ICC intermediate, and a destination ICC profile.
    If it helps, take a look at the posts by the previous Product Manager for Colour and Imaging, John Zimmerer. These posts apply to Mac OS X 10.3 and higher.
    ColorSync and printing -- Panther (1 of 2)
    http://lists.apple.com/archives/colorsync-users/2003/Dec/msg00320.html
    ColorSync and printing -- Panther (2 of 2)
    http://lists.apple.com/archives/colorsync-users/2003/Dec/msg00316.html
    /hh

  • Adobe Camera RAW (All Versions) Import Canon .CR2 / RAW images with an orange / green color cast.

    All versions of Adobe Camera RAW including the latest 7.3 import .CR2 images with a greenish / orange color cast.
    Tested on 7D, and 5D III
    Makes Hardwood floors, and flesh tones look abysmal.
    Canon's Digital Photo Professional renders the colors fine, as does ACDSee 5.0 Pro (when viewing)  Exporting from ACDSee however is another story as things look even worse than Adobe.  DPP can export perfectly.
    Changes to Color Gammut / Space have little or no effect.

    Good day!
    You might want to post on the dedicated Camera Raw Forum.
    http://forums.adobe.com/community/cameraraw
    Also posting some screenshots might help illustrate the issue.
    Regards,
    Pfaffenbichler

  • Image based of all the colors currently in the swatch

    Are there anyone who know a method or script that enables generation of an image based of all the colors currently in the swatch?
    I would want it to fill a grid, with a patch of the color with the colors name underneath it, and with the name of the swatch as a header on a black background. Maybe even with the lab, cmyk and rgb values underneath each color.
    The colors need to be arranged in the same manner as in the swatch.
    Any help would be appreciated.

    I'm sure this is possible, but you might want to post this in the scripting forum or on ps-scripts.com.  Here is a link to a topic along the lines that you want on ps-scripts.com:
    http://www.ps-scripts.com/bb/viewtopic.php?t=5161

  • Can I simply reinstall CS4 to resolve my operation problems?

    Can I simply reinstall Adobe CS4 (design std) on my Mac OS X to resolve my operation problems, such as "Unknown error" messges while using Ai and ID. My software has been trouble free for about a yr and half and suddenly several odd problems popped up in the last few months. If you think reinstalling will help, please give me a general direction for doing so. Thanks in advance!

    Hello,
    I heard that holding CMD+Option+r at bootup connects to Apple's servers & Lion download, hasn't been confirmed yet.

  • Problem with reversal of Service entry Sheet

    Hi All,
    I am facing a problem with reversal of service entry sheet. The user has posted the document in dec 2009 and now the user wants to reverse the doc. I told the process how to reverse it. But when she is trying to revoke the acceptance, she is getting error log.I told her to reset the posting date to present date.Now she tried to change the doc date but she is getting error as "604 item 010 WBS element ****** budget exceeded year 2009". So i advised her further to increase the budget in the year 2009. Even that solution is not working.
    Please help in this regard
    Thanks & Regards
    Nisha Prasad

    Hi,
    The user is not authorised to change the budget. The person resposible for this is telling that increasing the budget wont help. can you tell me how to view whether the budget is available for the system in the period or not? Can you please help me in this regard?
    Thanks
    Nisha

  • Problem in Reversing MIRO Document

    Hi Gurus,
    I am getting the  following problem when reversing the Miro, please help me in this reagrd.
    Balance not zero: 716.48  debits: 76,836.52  credits: 77,553.00
    Message no. M8534
    Diagnosis
    The system has discovered a difference between the debits and credits. This difference lies outside the tolerance limits set.
    System Response
    The system cannot post the document.
    Procedure
    If this message appears when you are processing a document online, you can
    change the amounts or enter new items until you can post the document
    change the Invoice Verification type, so that the document can be posted later in the background.
    If this message appeared when a document was verified in the background, you can now process the document.
    Regards
    Shree

    hi
    what cost ur entering in field of amount
    go to MIRO here do the normal process
    now just copy the amount from right top o the amount field
    plz check that u have ticked for calculate tax before copying amount
    now simulate and check
    regards
    KI

  • Camera RAW JPG 'Save image....' dialogue reversal?

    In camera RAW, to save a JPG you click on the 'Save image...' dialogue and another window opens with the JPG options.
    To skip this window and directly save the image, you hold down the ALT key and click on the 'Save image'.
    Is it possible to reverse these settings, so that if you want the JPG dialogue to open you have to hold down the ALT key and to save without the dialogue, you just click on the save button?

    Thank you, Mr. Spock!
    Very true. it would be counterintutive.
    But my left hand is stiff from holding the ALT key!
    Is it possible to redefine the keys in camera RAW?

  • Problem with reverse mapping

    Hi!
    I am having a problem with reverse mapping. Here's what I do (copying the
    generated files to a correct directory omitted):
    % rd-schemagen -properties jdo.properties -file schema.xml
    % rd-reversemappingtool -properties jdo.properties -package testi
    schema.xml
    % javac -d build/classes src/testi/*.java
    % rd-importtool -properties jdo.properties src/testi/testi.mapping
    Here's a part of the output:
    <clip>
    2958 INFO [main] jdbc.Schema - Found existing table "Kirja" for schema
    "null".
    3002 INFO [main] jdbc.Schema - Found existing table "Kustantaja" for
    schema "n
    ull".
    3047 INFO [main] jdbc.SQL - [C: 5948361; T: 15336018]close
    3125 INFO [main] jdbc.SQL - [C: 2478770; T: 15336018]open:
    jdbc:mysql://localh
    ost/kirjakauppa (root)
    3129 INFO [main] jdbc.Schema - Found existing table "Kirjailija" for
    schema "n
    ull".
    3140 INFO [main] jdbc.SQL - [C: 2478770; T: 15336018]close
    3187 INFO [main] jdbc.SQL - [C: 7529545; T: 15336018]open:
    jdbc:mysql://localh
    ost/kirjakauppa (root)
    3193 INFO [main] jdbc.Schema - Found existing table "Kirjoittaja" for
    schema "
    null".
    3225 INFO [main] jdbc.SQL - [C: 7529545; T: 15336018]close
    Exception in thread "main" javax.jdo.JDOFatalInternalException:
    java.lang.Illega
    lArgumentException: You are attempting to link to a primary key column in
    table "Kirja" in a foreign key that is already linked to primary key
    columns in table "Kirjailija".
    NestedThrowables:
    java.lang.IllegalArgumentException: You are attempting to link to a primary
    key column in table "Kirja" in a foreign key that is already linked to
    primary key c
    olumns in table "Kirjailija".
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.Mappings.createClassMapping(Ma
    ppings.java:160)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.MappingRepository.getMapping(M
    appingRepository.java:279)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.MappingRepository.getMetaData(
    MappingRepository.java:147)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.MappingRepository.getMapping(M
    appingRepository.java:158)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.compat.ImportTool.getMapping(I
    mportTool.java:126)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.compat.ImportTool.importMappin
    gs(ImportTool.java:57)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.compat.ImportTool.run(ImportTo
    ol.java:408)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.compat.ImportTool.main(ImportT
    ool.java:385)
    NestedThrowablesStackTrace:
    java.lang.IllegalArgumentException: You are attempting to link to a primary
    key column in table "Kirja" in a foreign key that is already linked to
    primary key c
    olumns in table "Kirjailija".
    at
    com.solarmetric.rd.kodo.impl.jdbc.schema.ForeignKey.join(ForeignKey.j
    ava:238)
    at
    com.solarmetric.rd.kodo.impl.jdbc.schema.SchemaGenerator.generateFore
    ignKeys(SchemaGenerator.java:625)
    at
    com.solarmetric.rd.kodo.impl.jdbc.schema.DynamicSchemaFactory.findTab
    le(DynamicSchemaFactory.java:111)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.map.BaseClassMapping.fromMappi
    ngInfo(BaseClassMapping.java:113)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.Mappings.createClassMapping(Ma
    ppings.java:144)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.MappingRepository.getMapping(M
    appingRepository.java:279)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.MappingRepository.getMetaData(
    MappingRepository.java:147)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.MappingRepository.getMapping(M
    appingRepository.java:158)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.compat.ImportTool.getMapping(I
    mportTool.java:126)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.compat.ImportTool.importMappin
    gs(ImportTool.java:57)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.compat.ImportTool.run(ImportTo
    ol.java:408)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.compat.ImportTool.main(ImportT
    ool.java:385)
    </clip>
    Here's what MySQLCC gives for creation statement of the tables:
    <clip>
    # Host: localhost
    # Database: kirjakauppa
    # Table: 'Asiakas'
    # CREATE TABLE `Asiakas` (
    `Asiakas_id` int(11) NOT NULL auto_increment,
    `Nimi1` varchar(50) default NULL,
    `Nimi2` varchar(50) default NULL,
    `KatuOsoite` varchar(50) default NULL,
    `Postiosoite` varchar(50) default NULL,
    `Email` varchar(50) default NULL,
    `Puhelin` varchar(50) default NULL,
    `Fax` varchar(50) default NULL,
    `Salasana` varchar(50) default NULL,
    `ExtranetTunnus` varchar(50) default NULL,
    PRIMARY KEY (`Asiakas_id`),
    KEY `Asiakas_id` (`Asiakas_id`)
    ) TYPE=InnoDB;
    # Host: localhost
    # Database: kirjakauppa
    # Table: 'Kirja'
    # CREATE TABLE `Kirja` (
    `Kirja_id` int(11) NOT NULL auto_increment,
    `Kustantaja_id` int(11) default NULL,
    `Nimi` varchar(60) default NULL,
    `Nimi2` varchar(60) default NULL,
    `ISBN` varchar(50) default NULL,
    `Kieli` varchar(50) default NULL,
    `Kansi_URL` varchar(50) default NULL,
    `Sisalto_URL` varchar(50) default NULL,
    `Tukkuhinta` decimal(10,2) default NULL,
    `Kuluttajahinta` decimal(10,2) default NULL,
    `Varastokpl` int(11) default NULL,
    PRIMARY KEY (`Kirja_id`),
    KEY `Kirja_id` (`Kirja_id`),
    KEY `Kustantaja_id` (`Kustantaja_id`),
    FOREIGN KEY (`Kustantaja_id`) REFERENCES `kirjakauppa.Kustantaja`
    (`Kustantaja_id`)
    ) TYPE=InnoDB;
    # Host: localhost
    # Database: kirjakauppa
    # Table: 'Kirjailija'
    # CREATE TABLE `Kirjailija` (
    `Kirjailija_id` int(11) NOT NULL auto_increment,
    `Sukunimi` varchar(50) default NULL,
    `Etunimi` varchar(50) default NULL,
    `Maa` varchar(50) default NULL,
    `Kirjailija_URL` varchar(50) default NULL,
    PRIMARY KEY (`Kirjailija_id`),
    KEY `Kirjailija_id` (`Kirjailija_id`)
    ) TYPE=InnoDB;
    # Host: localhost
    # Database: kirjakauppa
    # Table: 'Kirjoittaja'
    # CREATE TABLE `Kirjoittaja` (
    `Kirjoittaja_id` int(11) NOT NULL auto_increment,
    `Kirjailija_id` int(11) NOT NULL default '0',
    `Kirja_id` int(11) NOT NULL default '0',
    PRIMARY KEY (`Kirjoittaja_id`),
    KEY `Kirjailija_id` (`Kirjailija_id`),
    KEY `Kirja_id` (`Kirja_id`),
    FOREIGN KEY (`Kirjailija_id`) REFERENCES `kirjakauppa.Kirjailija`
    (`Kirjailija_id`),
    FOREIGN KEY (`Kirja_id`) REFERENCES `kirjakauppa.Kirja` (`Kirja_id`)
    ) TYPE=InnoDB;
    # Host: localhost
    # Database: kirjakauppa
    # Table: 'Koodi'
    # CREATE TABLE `Koodi` (
    `Koodi_id` int(11) NOT NULL auto_increment,
    `Koodi` varchar(50) default NULL,
    `Tyyppi` varchar(50) default NULL,
    `Arvo` varchar(50) default NULL,
    PRIMARY KEY (`Koodi_id`)
    ) TYPE=InnoDB;
    # Host: localhost
    # Database: kirjakauppa
    # Table: 'Kustantaja'
    # CREATE TABLE `Kustantaja` (
    `Kustantaja_id` int(11) NOT NULL auto_increment,
    `Nimi` varchar(80) default NULL,
    `Maa` varchar(50) default NULL,
    `Kustantaja_URL` varchar(50) default NULL,
    `KirjaLkm` int(11) default NULL,
    PRIMARY KEY (`Kustantaja_id`),
    KEY `Kustantaja_id` (`Kustantaja_id`)
    ) TYPE=InnoDB;
    # Host: localhost
    # Database: kirjakauppa
    # Table: 'Luokittelu'
    # CREATE TABLE `Luokittelu` (
    `Luokittelu_id` int(11) NOT NULL auto_increment,
    `Luokka_id` int(11) NOT NULL default '0',
    `Kirja_id` int(11) NOT NULL default '0',
    PRIMARY KEY (`Luokittelu_id`),
    KEY `Luokka_id` (`Luokka_id`),
    KEY `Kirja_id` (`Kirja_id`),
    FOREIGN KEY (`Luokka_id`) REFERENCES `kirjakauppa.Luokka` (`Luokka_id`),
    FOREIGN KEY (`Kirja_id`) REFERENCES `kirjakauppa.Kirja` (`Kirja_id`)
    ) TYPE=InnoDB;
    # Host: localhost
    # Database: kirjakauppa
    # Table: 'Luokka'
    # CREATE TABLE `Luokka` (
    `Luokka_id` int(11) NOT NULL auto_increment,
    `Luokka` varchar(50) default NULL,
    PRIMARY KEY (`Luokka_id`),
    KEY `Luokka_id` (`Luokka_id`)
    ) TYPE=InnoDB;
    # Host: localhost
    # Database: kirjakauppa
    # Table: 'Myyja'
    # CREATE TABLE `Myyja` (
    `Myyja_id` int(11) NOT NULL auto_increment,
    `Myyja` varchar(50) default NULL,
    `Myyja_URL` varchar(50) default NULL,
    PRIMARY KEY (`Myyja_id`),
    KEY `Myyja_id` (`Myyja_id`)
    ) TYPE=InnoDB;
    # Host: localhost
    # Database: kirjakauppa
    # Table: 'Tilaus'
    # CREATE TABLE `Tilaus` (
    `Tilaus_id` int(11) NOT NULL auto_increment,
    `Asiakas_id` int(11) NOT NULL default '0',
    `Myyja_id` int(11) default NULL,
    `TilausPvm` timestamp(14) NOT NULL,
    `EnsimmToimitusPvm` timestamp(14) NOT NULL,
    `ViimToimitusPvm` timestamp(14) NOT NULL,
    `Tila` int(11) NOT NULL default '0',
    `Mk` decimal(10,2) default NULL,
    PRIMARY KEY (`Tilaus_id`),
    KEY `Asiakas_id` (`Asiakas_id`),
    KEY `Myyja_id` (`Myyja_id`),
    KEY `Tilaus_id` (`Tilaus_id`),
    FOREIGN KEY (`Asiakas_id`) REFERENCES `kirjakauppa.Asiakas`
    (`Asiakas_id`),
    FOREIGN KEY (`Myyja_id`) REFERENCES `kirjakauppa.Myyja` (`Myyja_id`)
    ) TYPE=InnoDB;
    # Host: localhost
    # Database: kirjakauppa
    # Table: 'Tilausrivi'
    # CREATE TABLE `Tilausrivi` (
    `TilausRivi_id` int(11) NOT NULL auto_increment,
    `Tilaus_id` int(11) NOT NULL default '0',
    `Kirja_id` int(11) NOT NULL default '0',
    `TilausLkm` int(11) default NULL,
    `Ahinta` decimal(10,2) default NULL,
    `Alepros` float default NULL,
    `Mk` decimal(10,2) default NULL,
    `ToimitettuLkm` int(11) default NULL,
    `ToimitusPvm` timestamp(14) NOT NULL,
    `ViimToimitusPvm` timestamp(14) NOT NULL,
    `Tila` int(11) NOT NULL default '0',
    PRIMARY KEY (`TilausRivi_id`),
    KEY `Tilaus_id` (`Tilaus_id`),
    KEY `Kirja_id` (`Kirja_id`),
    FOREIGN KEY (`Tilaus_id`) REFERENCES `kirjakauppa.Tilaus` (`Tilaus_id`),
    FOREIGN KEY (`Kirja_id`) REFERENCES `kirjakauppa.Kirja` (`Kirja_id`)
    ) TYPE=InnoDB;
    </clip>
    I can find the original creation script if it is necessary.
    My guess was that I need to define the foreign keys myself into the
    generated schema.xml This is stated in the manual. However, this did not
    help, although it changed the stack trace a little (it complains about
    different classes than before):
    <clip>
    Exception in thread "main" javax.jdo.JDOFatalInternalException:
    java.lang.IllegalArgumentException: You are attempting to link to a primary
    key column in table "Myyja" in a foreign key that is already linked to
    primary key columns in table "Asiakas".
    NestedThrowables:
    java.lang.IllegalArgumentException: You are attempting to link to a primary
    key column in table "Myyja" in a foreign key that is already linked to
    primary key columns in table "Asiakas".
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.Mappings.createFieldMapping(Mappings.java:208)
    </clip>
    I don't think I fully understand the error message, what exactly is wrong
    here? How can I fix it?
    Here's a sample of the changes I made to schema.xml:
    - added the name - attribute to schema (it was missing)
    <schema name="kirjakauppa">
    - added the foreign key elements according to the table creation statements
    given above
    <fk name="Kustantaja_id" to-table="Kustantaja" column="Kustantaja_id"/>
         etc...
    -Antti

    On Mon, 16 Jun 2003 17:55:35 -0500, Abe White <[email protected]>
    wrote:
    It seems the last three options are being ignored - I still get a
    mapping
    file with schema names in front of tables (e.g. kirjakauppa.Asiakas, not
    Asiakas),That, unfortunately, is impossible to turn off. The -useSchemaName
    option controls whether the schema name is included as part of the
    generated class name; it doesn't affect the mapping data that is
    generated. What problems does including the schema name in the mapping
    data cause?
    rd-importtool -properties jdo.properties gensrc/testi/testi.mapping0 INFO [main] kodo.MetaData - Parsing metadata resource
    "file:/home/akaranta/work/kurssit/jdo/Harjoituskoodi/kirjakauppa/gensrc/testi/testi.mapping".
    Exception in thread "main"
    com.solarmetric.rd.kodo.meta.JDOMetaDataNotFoundException: No JDO metadata
    was found for type "class testi.Asiakas".
    FailedObject:class testi.Asiakas
    at
    com.solarmetric.rd.kodo.meta.JDOMetaDataRepositoryImpl.getMetaData(JDOMetaDataRepositoryImpl.java:126)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.MappingRepository.getMetaData(MappingRepository.java:184)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:197)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.compat.ImportTool.getMapping(ImportTool.java:128)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.compat.ImportTool.importMappings(ImportTool.java:60)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.compat.ImportTool.run(ImportTool.java:400)
    at
    com.solarmetric.rd.kodo.impl.jdbc.meta.compat.ImportTool.main(ImportTool.java:377)
    This exception goes away if I edit the schema name out of the mapping
    file from all classes.
    separate classes are being generated for join tables with
    primary keysDo these join tables have an extra primary key column? TheYes, they do. Ok, now I know where the problem is.
    -primaryKeyOnJoin flag tells Kodo to ignore a join table with a primary
    key on the join columns. But Kodo can't handle join tables with extra
    column(s) just for a primary key identifier. This isn't a limitation of
    the reverse mapping tool, it's a limitation of Kodo. Kodo wouldn't know
    what to insert in those extra primary key column(s) when adding membersWhy not? If it can handle single numeric pk columns when making the
    generated classes use data store identity, it has to generate something to
    those columns. I can't see why this is different.
    That is simply out of curiosity - the next thing fixed my problem:
    to the join table. Of course, if the primary key is an auto-increment or
    something where Kodo can ignore it for inserts, you can just remove the
    <column> elements and the <pk> element from your .schema file and the
    reverse mapping tool will map it as a join table appropriately.It is auto-increment, so I did this and it worked. Thanks.
    , and application id is used for all classes.Are your primary keys on single, numeric columns? Kodo uses Java longsYes (int in MySQL), so that should not be a problem. They are also auto-
    incremented. This seems to be the only real problem remaining with this
    schema.
    -Antti

Maybe you are looking for

  • G5 won't boot from any drive (internal or external)

    I've been studying this forum for the last several days, hoping to find something to help me solve the problem, but so far I'm still stuck. Here's the deal... I bought a refurbished G5 2.7DP (early 2005) from Apple's Online Store and got it about a w

  • W530 Nvidia 2100m Projector Issues

    Hi, I am having problems when connecting to projectors. For some projectors, it only allows me to connect to them when I choose "only projector" mode, not extended or duplicate. Even when I can connect, videos often are unplayable because intense vid

  • Switch on open item mangement.-ERROR

    We are in version Ecc 6.0 ,We have a Balancesheet Gl account.We have made the balance equal to zero.And now want to switch on open item mangement. But it displays below message: Account balance =0 but open items exist in the account The data contains

  • Hierchical wth null and holes

    I am trying to mine the DBA_HIST_ACTIVE_SESS_HISTORY. The column that interrest me are 'sample_time','session_sid','session_serial#', 'blocking_session' and blocking_Session_serial#'. The purpose is to list per sample time the blocking session tree (

  • Keyboard lock and password request

    Hi, Can anyone please help me with the following: When taking a call my key pad is not locking and I keep putting people on hold/mute etc when talking to them. Also voice mail keeps requesting I set up voice mail when I have already done so. Cheers J