Code generation example

Hi again,
Does somebody have a small example for of some plsql code that actually generates plsql code?
I' trying something like below but it does not seem to work ...
TIA,
Stefan
CREATE OR REPLACE PROCEDURE TstCodeGen(tbl_name IN VARCHAR2)
IS
sqltext varchar2(10240);
BEGIN
DBMS_OUTPUT.PUT_LINE('Start');
sqltext := 'CREATE OR REPLACE PROCEDURE testGenerated IS' || chr(10);
sqltext := sqltext || 'TYPE tbl_name_TYPE IS REF CURSOR;' || chr(10);
sqltext := sqltext || 'tbl_names_cu tbl_name_TYPE;' || chr(10);
sqltext := sqltext || 'num_records INTEGER;' || chr(10);
sqltext := sqltext || 'mytabnames ' || tbl_name || '%ROWTYPE;' || chr(10);
sqltext := sqltext || 'sql_select_table_names varchar2(200);' || chr(10);
sqltext := sqltext || 'sqltxt varchar2(200);' || chr(10);
sqltext := sqltext || 'BEGIN' || chr(10);
sqltext := sqltext || ' sql_select_table_names:=''SELECT * FROM '||tbl_name||''';' || chr(10);
sqltext := sqltext || ' execute immediate sql_select_table_names;' || chr(10);
sqltext := sqltext || 'END;' || chr(10);
sqltext := sqltext || '/' || chr(10);
DBMS_OUTPUT.PUT_LINE(sqltext);
execute immediate sqltext;
DBMS_OUTPUT.PUT_LINE('sqltext executed??');
sqltext := 'exec testGenerated;';
execute immediate sqltext;
DBMS_OUTPUT.PUT_LINE('Done');
END;
show errors;

I would say extremly weird and definitely of no real practical use ... but at least doable, when the correct syntax is applied:
SQL> CREATE OR REPLACE PROCEDURE tstcodegen (tbl_name IN VARCHAR2)
  2  IS
  3     sqltext   VARCHAR2 (10240);
  4  BEGIN
  5     DBMS_OUTPUT.put_line ('Start');
  6     sqltext := 'CREATE OR REPLACE PROCEDURE testGenerated IS' || CHR (10);
  7     sqltext := sqltext || 'TYPE tbl_name_TYPE IS REF CURSOR;' || CHR (10);
  8     sqltext := sqltext || 'tbl_names_cu tbl_name_TYPE;' || CHR (10);
  9     sqltext := sqltext || 'num_records INTEGER;' || CHR (10);
10     sqltext := sqltext || 'mytabnames ' || tbl_name || '%ROWTYPE;' || CHR (1
0);
11     sqltext := sqltext || 'sql_select_table_names varchar2(200);' || CHR (10
12     sqltext := sqltext || 'sqltxt varchar2(200);' || CHR (10);
13     sqltext := sqltext || 'BEGIN' || CHR (10);
14     sqltext :=
15        sqltext || ' sql_select_table_names:=''SELECT * FROM ' || tbl_name
16        || ''';' || CHR (10);
17     sqltext :=
18            sqltext || ' execute immediate sql_select_table_names;' || CHR (1
0);
19     sqltext := sqltext || 'END;';
20  -- sqltext := sqltext || '/' || CHR (10);
21     DBMS_OUTPUT.put_line (sqltext);
22
23     EXECUTE IMMEDIATE sqltext;
24
25     DBMS_OUTPUT.put_line ('sqltext executed??');
26     sqltext := 'begin testGenerated; end;';
27
28     EXECUTE IMMEDIATE sqltext;
29
30     DBMS_OUTPUT.put_line ('Done');
31  END tstcodegen;
32  /
Prozedur wurde erstellt.
SQL>
SQL> SHOW errors;
Keine Fehler.
SQL>
SQL> EXEC tstcodegen('emp')
Start
CREATE OR REPLACE PROCEDURE testGenerated IS
TYPE tbl_name_TYPE IS REF
CURSOR;
tbl_names_cu tbl_name_TYPE;
num_records INTEGER;
mytabnames
emp%ROWTYPE;
sql_select_table_names varchar2(200);
sqltxt varchar2(200);
BEGIN
sql_select_table_names:='SELECT * FROM emp';
execute immediate
sql_select_table_names;
END;
sqltext executed??
Done
PL/SQL-Prozedur erfolgreich abgeschlossen.

Similar Messages

  • Simple Code Generation Example(s) Sought

    PROBLEM
    How can I generate a java bean (i.e. getters & setters) for property names that are to be read from an external text file. In other words, I want to read in a list of property names and then create a java bean with getters and setters based on that list.
    I know that they're some very sophisticated tools out there that do this and way much more. However, I would very much like to build a very simple class that does all the above.
    NAIVE PLAN
    I'm thinking of printing out java code to an external file and then trying to see how to compile it. When done, I would delete the dynamically created .java file and the associated .class file.
    WERE I CAN USE SOME HELP
    Can any of you point me in the right direction or provide a code snipplet(s) that illustrate the main points?
    Thanks!

    NAIVE PLANI'm thinking of printing out java code to an external file and then trying to see how to compile it. When done, I would delete the dynamically created .java file and the associated .class file.
    do you mean u want to generate .java files from your .properties file?
    why not create one class of JavaBean that can handle a diff properties?
    public class JavaBeanX extends Properties {
       public Object get(String field) {
          retrun getProperty(field);
       public void set(String field, Object val) {
          setProperty(field, val);
    }you can load from file using JavaBeanX.load(InputStream) and store it to using JavaBeanX.store(OutputStream).

  • FPGA Code Generation fails with error codes 7 and -1

    Hi all,
    I have been having a weird issue with my LV FPGA compilation in the last couple of days, no matter what I try to compile LV fails to generate the FPGA code files and returns with errors 7 and -1 and complains that the file is not found. This happens no matter what I am trying to compile even a VI with just a while loop. I followed the discussion forum here without any luck, also followed the NI article here and that did not help either. The error codes always get generated at the start of the Generating Intermediate files step #7 (out of 7).
    Attached to this post is a screenshot of the error I am getting (error -1 just says internal error and to contact NI support), bellow is basically the error I get for error code 7
    An internal software error has occurred. Please contact National Instruments technical support at ni.com/support with the following information:
    Error 7 occurred at Read from Text File in nirviGetInstantiation_cRIO-IDSel_Timer.vi->nirviGetInstantiation_cRIO-IDSel_Timer.vi.ProxyCaller
    Possible reason(s):
    LabVIEW: File not found. The file might have been moved or deleted, or the file path might be incorrectly formatted for the operating system. For example, use \ as path separators on Windows, : on Mac OS X, and / on Linux. Verify that the path is correct using the command prompt or file explorer.
    =========================
    NI-488: Nonexistent GPIB interface.
    C:\NIFPGA\compilation\cRioController_8-SlotFPGA_FPGA-TriggerTest_C06156E2\IDSel_Timer.vhd
    I tried to do some digging to see what could possibly be happening, and I noticed that LV is looking for the vhdl files in the wrong folder (see the line highlighted in red above), when generating the vhdl files, LV will place them inside the "source_files" folder under the compilation project, but for some reason it is trying to find them under the root folder not inside the source_files folder!!!
    Does anyone have any idea why LV would be looking for these files in the wrong subfolder? 
    Thank you,
    Aws
    Attachments:
    Code Generation Errors.png ‏35 KB

    Hi Aws_Khudhair,
    What version of LabVIEW are you using? And what version of the FPGA module? From what I found, it seems as though this is primarily an issue with LabVIEW 8.6 and 8.6.1.
    http://digital.ni.com/public.nsf/allkb/A711119FE89E39E78625754E00075E92
    This forum also discusses a similar issue:
     http://forums.ni.com/t5/Real-Time-Measurement-and/FPGA-compile-errors-after-generating-intemediate-f...
    It may also be worth repairing/reinstalling the FPGA Module and the Xilinx compile tools.
    Catherine B.
    Applications Engineer
    National Instruments

  • UML code generation

    Hi,
    I'm developing an application of ~50+ classes in UML on JSE8 and use java code generation.
    The question is about aggregations.
    Navigable aggregations translate in java code to a class attribute, and to the corresponding getter/setters-methods.
    A non-navigable aggregation is not translated to java code at all.
    ( I would expect it should translate to an attribute, but without getter/setters.
    My understanding is, "navigable" means "navigable from outside the class". Correct?)
    So how can I model an aggregation, which translates to an attribute in java, without generating the getters/setters?
    And where can I find a comprehensive list of how elements in class diagrams are translated to java code?
    Where is the JSE8-UML-manual, which includes all these details about UML code generation?
    Thanks a lot for any useful hint!

    Hi,
    actually, the code generator is correct.
    A non-navigable association should not generate an attribute.
    Consider the example:
    class Order -> class Date
    You have navigation from class order to class date, but not otherwise.
    This means that, given a Order object, you can find it's associated Date.
    However, the inverse is not true: given a Date object you have no means of "navigating" or finding out which Order objects would have that date. This is what navigation means.
    This should be translated into something like this
    class Order{
    Date theDate;
    class Date{
    int day, whatever;
    //no ref to order-non navigable
    If navigation from both classes were possible, a much more complicated code would be needed. It would be something along these lines, considering a 1-1 association (a *-1 association would require multiple order references to be stored at Date, with yet more complications):
    class Order{
    Date theDate;
    void setDate(Date d)
    theDate=d;
    d.setOrder(this);
    class Date{
    int day,whatever;
    Order theOrder; //navigation to order
    void setOrder(Order o)
    theOrder=o;
    Care should be taken to ensure proper consistency between references (ie: the order in date should never be changed without making a corresponding change to the new order object).
    All this serves to show, you should use navigation sparringly (as needed) , otherwise you're just complicating your code more than you should.
    Greets
    Jorge

  • Mappings code generation : regular SQL / cursor PL/SQL

    Hi,
    When designing mappings, I fear that code generation can be potentially dangerous, because OWB automatically chooses the best method to generate the code (regular SQL or PL/SQL).
    I am looking for some examples where code generation for a mapping:
    - gives a regular SQL statement
    - gives a cursor-based PL/SQL
    - a small change in a mapping makes a regular SQL mapping to be transformed in a cursor-based PL/SQL
    Thank you
    Alexandre
    Message was edited by:
    Alexandre Abric

    I have not said that different modes executes at the same way – what the use to have different options if they actually mean the same, right? I have said that they produced the same result i.e. if you expect the mapping to insert 1000 rows from the source to the target – it will be done no matter which operation mode you choose.
    But by different ways. To keep it simple lets say that:
    set base mode will result in:
    insert into target (…)
    select … from source;
    row based will result in:
    begin
    for a in (select * from source) loop
    insert … into target
    end loop;
    end;
    Now lets assume that 5 rows from those 1000 you are going to insert, will break some NOT NULL constraint at the target.
    If you choose Set-base mode entire insert from select will fail resulting no rows is inserted into target. Audit trail will contain message like “constraint … violated” and that’s it. You will have to find bad records by yourself.
    If you choose Row-base mode – 995 rows will be inserted (depending on mapping configuration) into the target and 5 will be listed in audit trail with the same “ constraint violated” message.
    That’s why default operating mode is “Set based fail over to Row based”. That means OWB will try to execute mapping in the fastest way – set based, but if it fail, it will try again to accomplish the task by running in row base mode, providing complete audit trail fro bad rows.

  • Enhanced Flash Builder Code Generation Functionality

    For voting in JIRA:
    https://bugs.adobe.com/jira/browse/FB-27169
    The code generation feature FB 4 currently has is only really useful for quick throwaway prototyping or very simple forms. The generation should allow you to configure formatting via default templates, AND optionally utilize a dialog box (similar to that used in refactoring but with a few extras) so that you can configure the contents of each generated function and provide appropriate function names according to coding best practices. For example:
    -User initiates event handler generation
    (Optional, if Codegen dialog is enabled)
    -User is prompted with a dialog that allows them to customize the generated function name, and possibly specify whether they need an Event parameter passed to the function. (Default to NO event parameter, but this could be a pre-configured user option.)
    -FB utilizes the customized code generation format (customizable by the developer) to generate the new function
    If you need a "submitForm()" function and you want both a TextInput's enter action and a button's click action to call it, currently you're better off typing it all yourself, because auto-generation is going to put this long-named function that assumes you need 'event' passed to it. An event:MouseEvent parameter just gets in the way when you also want a TextInput's enter event to call that function, for example. Or perhaps we want to provide a more descriptive name to each handler (via dialog) without assigning IDs to each and every component: "datagrid1_changeHandler" or "button1_changeHandler" doesn't tell us what the function actually does. It's a basic coding best practice to name functions or methods after the actions they actually perform, and in a large application with complex forms auto-generated generic sounding function names are essentially useless from a maintainability standpoint.

    For anyone interested, I figured it out:
    to generate a CFC, you have to right-click a table in the RDS Dataview, then you can generate a CFC. You cannot generate a CFC from an AS class as described in the CF Builder help within Flash Builder.
    Adobe: it would be nice if this got fixed – and if someone there replied to posts like this. You do  know all this, don‘t you?

  • NI Motion Assistant LabVIEW Code Generation Error

    Hello, the following is my current setup:
    NI PCI-7334 motion control board
    NI UMI 7774 splitter board
    3 x NI P70530 Drives
    3 x NI CTP12ELF10MAA00 Stepper Motors
    3 x Power supply units for drives
    LabVIEW 2010
    NI Motion Assistant 2.6
    Motion and Automation Explorer 4.7
    I have built a three axis motion system that I am trying to configure with labview. After verifying that everything was set up correctly, I opened MAX, updated the firmware to my motion control board, and intitialized the controller. Since then, I have created many basic programs using the Motion Assistant Software to test the movement of my device. Everything works fine while using the Motion Assistant software (I have three axis movement, multidirectional control, and can perform various straight line and arc moves). My problems begin when I try to use the code generation feature.
    When trying to use the code generation feature to output a labview diagram, I run into a problem where a dialog box pops up and says "Find the vi named ...."
    Some examples of the names that come up are: Configure Vector Space.flx, Vector Space To Control.flx, Motion Error Handler.flx.
    To be clear the program in Motion Assistant that I am trying to export to LabVIEW code is composed of two individual steps. One that tells X,Y, and Z motors to move forward 25 revolutions, and one step that tells them to move backwards 25 revolutions.
    I have made many other programs in Motion Assistant that run fine, but I always receive similar errors when trying to use the code generation feature to export to LabVIEW. Is there something that I can do to solve my problem?
    Thank you for your help.

    Hi Joe,
    I am using Ni-Motion Assistant 2.6, Ni-Motion 8.1, and Motion and Automated Explorer version 4.7.
    The code I posted is supposed to tell Axis 1 to move 40 revolutions at 400 rpm. It works fine in Ni-Motion Assistant but when I try to generate a LabVIEW diagram I receive the following error, "Find the VI named 'Motion Error Handler.flx'". I have had it search my directory, as well as the disk that I installed both LabVIEW and Ni-Motion but no luck. Thanks for your help.
    Attachments:
    1111.vi ‏9 KB
    1 axis movement.zip ‏8 KB

  • Code 'Generation' with DRY (don't repeat yourself)??

    Hello I am new to the forum so please be kind,
    I have recently gotten an internship with one of the offices with my University and am working a project (for a while now). I spend most of the day just getting all the classes assembled to be used (often a two day process) and what I would like to do is pass in a few parameters then have it generate the majority of the standard code that takes so much time to type out.
    What I am referring to is Consructors/ Setters/ Getters and toString.
    Parameters:
    Class name
    int first 5
    double secondMost of this stuff is pretty standard, but I figured there was a template or something I could build to do much of this for me. Unfoturnaly the University teaches C++, so learning Java on my own is somewhat difficult at times.
    Oh. I had found a wikipedia page about a design method called DRY, basically it pointed out that I could do just what I am wanting to do, but unfortunately I cannot seem to find an example or any detailed information about this method.
    This is what I have rolling around in my head at the moment:
    The use a bunch of strings and printf("%s, args) ...to build this entire page, then go in and enter the things that I couldn't generate.
    I could see this working, but I had felt this would go against code resuability because when the class/things I would generate would change, I would have to do some serious changes to this to get it working again. (Maybe that is the point).
    I would greatly appreciate some guidance on this, or pointed to more information.
    Thanks

    dajohnson1s wrote:
    Hello I am new to the forum so please be kind,
    I have recently gotten an internship with one of the offices with my University and am working a project (for a while now). I spend most of the day just getting all the classes assembled to be used (often a two day process) and what I would like to do is pass in a few parameters then have it generate the majority of the standard code that takes so much time to type out.
    What I am referring to is Consructors/ Setters/ Getters and toString.
    Parameters:
    Class name
    int first 5
    double second
    Most of this stuff is pretty standard, but I figured there was a template or something I could build to do much of this for me. Unfoturnaly the University teaches C++, so learning Java on my own is somewhat difficult at times.
    First step is recognizing a pattern.
    Second step, experience wise, is learning to recognize the difference between something that should be generated and something that shouldn't.
    Third step is implementation.
    Code generation should only be used if it can be insured that it eases the task now and in addition does not complicate the task in the future. That must include the possibility that the generation part will be abandoned so the generated code itself must be in such a state that it can be maintained.
    Once you have a pattern then you must choose a way to represent the pattern as a 'source'. Sources can one or more of the following: text, xml, sql scripts, sql databases, existing source files, existing code bases, design document, pdf files. Anything that you can extract a definition from will work.
    An example text file relevant to your task might look like this.
          Class: XxxMyclas
          Attribute: Count int
          Attribute: Name String.From that you create a standard compiler type idiom
    1. Parse (read file and collect data)
    2. Syntax (validate collected data, which might also be part of 1)
    3. Generate (use data to generate new source)
    Each phase can embodied certain complications (can not must). Some examples.
    1. Parse - provide an xml to define data types.
    2. Generate - provide a template file used to generate the code, define where the output goes, insure existing files not overwritten, etc.
    Your description sounds like a one shot - in that you will not be generating every everytime but rather will generate it once and then modify it.
    Oh. I had found a wikipedia page about a design method called DRY, basically it pointed out that I could do just what I am wanting to do, but unfortunately I cannot seem to find an example or any detailed information about this method.
    The only general books I have found on the subject is one directed at Perl (Perl Munging) which is sort of related and one for .Net (or maybe java) but which is directed at a proprietary commercial product.
    This is what I have rolling around in my head at the moment:
    The use a bunch of strings and printf("%s, args) ...to build this entire page, then go in and enter the things that I couldn't generate.
    I could see this working, but I had felt this would go against code resuability because when the class/things I would generate would change, I would have to do some serious changes to this to get it working again. (Maybe that is the point).
    Code generation has its best usage if you can recognize a pattern and then implement it such that manual modifications are not needed. This however is tempered by the requirement that I first mentioned that the generated code must be maintainable by itself.

  • Code generation problem with deployejb !

    I am working with Oracle 8.1.5 and jdk 1.1.6,
    when I am running the deployejb tool with the HelloWorld example of the demo directory, I have a problem with the code generation of the EJBHome and EJBObject:
    deployejb -u ...
    ... [deployejb found HelloHome.class]
    done
    Generating EJBHome and EJBObject on the server...
    An exception occured during code generation: Class not found : hello.HelloHome.class
    Note my CLASSPATH variable is correctly set.
    Can you HELP me ?
    null

    Adding -W2,-Rcond_elim to the existing flags does make both the small example and the original code compile correctly.
    --David                                                                                                                                                                                                                                                               

  • Code generation don't work - please help!

    Hi all
    just installed flash builder 4.5 , then installed the flash builder 4.5.1 update patch
    I've noticed the code generation features are not working
    meaning for example if I write "fori" in a function then hit ctrl+space
    it opens up an empty window with no suggerstions
    same goes when I tried generating variables, functions, classes, getters, setters ect...
    any idea as to why does it happen or what can I do about it?
    cheers

    Can you try a few things please -
    1. Post the content of your workspace log here. Log can be found in <workspace location>/.metadata/.log
    2. Post the steps you performed (starting from creating a new project) along with the .as and .mxml files. If you can't post your files here, please mail them to me at sameer[at]adobe[dot]com
    3. Create a new workspace using File > Switch Workspace > Other. Create a new Flex project in the workspace and try these features.
    Let me know your findings.

  • Business partner auto code generation

    hi how to create business partner auto code generation. its based on customer group for example we have more customer group..dealer, distributor,subcontractor...
    here dealer and distributor group starting cardcode is - C000001,C000002,C000003..... etc
    when i was choose subcontractor its starts SUB00001,SUB00002...... etc
    vendor is maintain same starting letter in all groups V000001,V000002
    Thanks in advance
    Thanks & Regards
    B.Lakshmi Narayanan

    hi thanks for your valuable replies...
    i changed the codes...pls check its right or wrong
    declare @temp as char(20)
    IF $[OCRD.GroupCode] = 104  and $[OCRD.cardtype] = 'c'
    BEGIN
    set @temp=(select isnull(max(right(cardCode,7)),0) + 1 from Ocrd where (groupcode= 104) and (len(cardCode)=7))
    set @temp='TRA'isnull(replicate(0,7-len(@temp)),'')@temp
    select cast(@temp as char(20))
    END
    ELSE IF $[OCRD.cardtype] = 'C'
    BEGIN
    set @temp=(select isnull(max(right(cardCode,7)),0) + 1 from Ocrd where   (len(cardCode)=7))
    set @temp='C'isnull(replicate(0,7-len(@temp)),'')@temp
    select cast(@temp as char(20))
    END
    ELSE IF $[OCRD.cardtype] = 'S'
    BEGIN
    set @temp=(select isnull(max(right(cardCode,7)),0) + 1 from Ocrd where   (len(cardCode)=7))
    set @temp='S'isnull(replicate(0,7-len(@temp)),'')@temp
    select cast(@temp as char(20))
    END
    Thanks & Regards
    B.Lakshmi Narayanan

  • Customization of OWB code generation

    Does OWB allow end-user to do tweaks in the code generation process?
    I am looking to do several things that cannot be done (or not easily be done) by OWB. For examples, in error reporting, I want to save row ID(s) of the error record(s) and error messages to a separate table. I want to call a procedure with several parameters at the end of a mapping process. If OWB allows user to insert extra code or replace certain piece of code, my problem could be solved easily.
    Thanks!

    Documents on generated code.
    Below are two suggestions. To summarize, Warehouse Builder is guaranteed to generate the most efficient code that takes advantage of all the features of a given version of Oracle database while automatically providing full auditing capability.
    "Oracle 9i Warehouse Builder Architectural White paper". You can skip to just page 12, "Transforming and loading" section. http://otn.oracle.com/products/warehouse/pdf/OWB_Architecture_WhitePaper.pdf
    "Integration of Oracle9i Warehouse Builder and Oracle9i". it's only 6 pages long.
    http://otn.oracle.com/products/warehouse/pdf/Oracle9i_OWB_whitepaper.pdf
    Nikolai

  • NI Veristand 2014 doesn't appear in MATLAB R2014a Code generation

    Hi
    I installed NI Veristand 2014 after installing MATLAB R2014a. I restarted my PC and tried to apply the sinewave example. I looked at code generation in Simulink model configuration parameters but couldn't find the NIVeristand option as illustrated in video. Here is a screenshot of system target file:
    Did I miss installing something? That was my installation (since I need Veristand to compile MATLAB model):
    Thanks for your assistance in advance
    Waleed El-Badry MSc.,MCPD, ISTQB Certified Tester
    Assistant Lecturer
    Mechatronics Department
    Faculty of Engineering
    Misr University for Science & Technology
    Solved!
    Go to Solution.

    Hi Waleed,
    Unfortunately the behavior your are experiencing is a fault in our installer's auto-detection of MATLAB R2014a. The NI VeriStand 2014 node you see in the installer setup window is actually hiding several other unique options. The default selections should auto-select MATLAB support if MATLAB was successfully detected by our installer, unfortunately this procedure has failed.
    To workaround this:
    1. Relaunch the installer setup window
    2. In the Features setup window (your second picture), left click on the image next to the NI VeriStand 2014 label
    3. You should now be presented with the option, Install with customization - select this option.
    4. Proceed with the installation, eventually you be presented with custom options for the VeriStand product.
    5. In the VeriStand feature list, select the NI VeriStand 2014 Model Framework option
    6. Proceed with the installation.
    After this, restart MATLAB and then relaunch. If the installation was successful, on relaunch of  the MATLAB COmmand Window will print the string Initializing NI VeriStnad 2014. Please note that we've documented this issue and are making an effort to address it.
    Nestor

  • JavaBeans code generation from XSD

    Hi everyone,
    I know that this is not a new question, but I still did not find a satisfying answer.
    Does anyone know a good code generator for creating JavaBeans out of XSD schemas?
    The output of this tool has to comply with the JavaBeans specification, because we want to map these POJOs to a database with the Java Persistence API. Especially lists and sets need to be created correctly, because we will make heavy use of associations.
    I've evaluated a large number of tools, most of them are not useable together with JPA. Here is a short list of tools I already tried:
    - Castor: Really nice tool, but getter-methods for "java.util.List" objects return a copy of this list as array! Output is not a JavaBean!
    - XMLBeans: As far as I've seen, Java objects have to be retrieved via a factory method, I see no possibility to use this library together with JPA. I furthermore doubt that these objects are JavaBeans.
    - HyperJaxb2+3: This tool promises to create Java POJOs and Hibernate mappings at the same time. The description looks very good, but the page seems to be down. I was not able to initiate a download for days.
    - Altova XMLSpy: This tool allows the generation of Java code out of XSD schemas. But the result is rather ugly. A simple XML "string" is translated into an internal Java class definition instead of a simple "String" instance. I see no usage of these objects together with JPA.
    I spent quite a lot of time for searching a good code generation framework that works together with JPA. Has anyone made good experience with any kind of code generators in this area?
    Thanks for any help!
    Martin

    Hi dvohra09,
    thanks for your reply. I think JAXB has the same limitations than XMLBeans. As I read at http://java.sun.com/javaee/5/docs/tutorial/doc/JAXB6.html, object instances shall be only accessed via a factory:
    "You should never directly use the generated implementation classes--that is, *Impl.java in the <packagename>/impl directory. These classes are not directly referenceable because the class names in this directory are not standardized by the JAXB specification. The ObjectFactory method is the only portable means to create an instance of a schema-derived interface. There is also an ObjectFactory.newInstance(Class JAXBinterface) method that enables you to create instances of interfaces. "
    Did you use JAXB2 together with the Java Persistence API? If yes, can you give me please an example how to map generated classes to the database?
    Thanks for your help!
    Martin

  • Hibernate + Middlegen + Code generation

    I use Hibernate and Middlegen for working with Oralce database. Middlegen generated java classes successfully. But I want to add some new methods and attributes to it. Can I specified that modification and apply it every time when I regenerate classes?
    For example: it generates class A:
    public class A {
    private BigDecimal xmlFile;
    public A() {};
    and i want to generate class as
    public class A {
    BigDecimal xmlFile;
    // new property that is not mapped on the database.
    int new_prop;
    public A() {
    // read data from file and specify new_prop.
    new_prop = 2;
    }

    I think Code Generation has it's place, and that place is pretty narrowly defined. I don't mind using a tool to generate boilerplate code that I already understand, but don't care to write. I don't mind asking my editor to generate get/set methods for me. I don't care if I never write another ejb-jar.xml. But I think it negatively effects your ability to write solid code when your understanding of what you're doing ends at the XDoclet tag.

Maybe you are looking for