Jfinal Connect to Oracle database generate multiple primary key solutions in Mappingkit file with foreign key as primary key

Source: Internet
Author: User

1 Listen to the wave is always said to be OJDBC this jar package version problem I used the ojdbc14 I replaced 6 and then there is this problem, so I rewrote the jfinal source inside the method is the second method

2 The following is the class I rewrote

Package Com.syhz.model;

Import Java.sql.ResultSet;
Import java.sql.SQLException;

Import Javax.sql.DataSource;

Import Com.jfinal.kit.StrKit;
Import Com.jfinal.plugin.activerecord.generator.MetaBuilder;
Import Com.jfinal.plugin.activerecord.generator.TableMeta;
/**
* Overriding jfinal generating primary key rules
* @author String
*
*/
public class Mymetabuilder extends metabuilder{

Public Mymetabuilder (DataSource DataSource) {
Super (DataSource);
TODO auto-generated Constructor stub
}

@Override
public void Buildprimarykey (Tablemeta tablemeta) throws sqlexception{

ResultSet rs = Dbmeta.getprimarykeys (Conn.getcatalog (), NULL, tablemeta.name);

String PrimaryKey = "";
int index = 0;
while (Rs.next ()) {
/*if (index++ > 0) {
PrimaryKey + = ",";
}*/
PrimaryKey = rs.getstring ("column_name");
}
if (Strkit.isblank (PrimaryKey)) {
throw new RuntimeException ("PrimaryKey of Table \" "+ Tablemeta.name +" \ "required by active record pattern");
}
Tablemeta.primarykey = PrimaryKey;
Rs.close ();


}
}

The words used were in 2 Generator.setmetabuilder (new Mymetabuilder (DATASOURCE2)); Mymetabuilder with his own rewrite.

The reason for marking 1 2 is to use one first to obtain because it is common sense that they will write a separate connection to the database method if you write a method to use it directly here will be an error message that the data is connected is the meaning of the duplicate connection so I did it.

Jfinal Connect to Oracle database generate multiple primary key solutions in Mappingkit file with foreign key as primary key

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.