Skip to main content

Posts

How to view relationships between Primary keys and Foreign keys in your Oracle Database

The following sql statement allows you to view the relationships between primary keys and foreign keys with other tables. SELECT uc.constraint_name||CHR(10)    || '('||ucc1.TABLE_NAME||'.'||ucc1.column_name||')' constraint_source    , 'REFERENCES'||CHR(10)    || '('||ucc2.TABLE_NAME||'.'||ucc2.column_name||')' references_column     FROM user_constraints uc ,     user_cons_columns ucc1 ,     user_cons_columns ucc2     WHERE uc.constraint_name = ucc1.constraint_name     AND uc.r_constraint_name = ucc2.constraint_name     and ucc1.position        = ucc2.position     AND uc.constraint_type   = 'R'     --AND uc.constraint_name   = 'FKF32F2C126588DBBC'     order by ucc1.table_name ,     uc.constraint_name;     CONSTRAINT_TYPE (from 11gR2 docs) C - Chec...

How to rename hibernate auto generated Foreign key constraint names

When using hibernate maven plugin to generate your tables you may have noticed hibernate generates obfuscated foreign key constraint names which are unreadable. In order to change the constraint names you can apply the @ForeignKey annotation to give your foreign keys more meaningful names as shown below. Take note if you take this approach you will need to take by insuring no duplicate constraint names are created. import @org.hibernate.annotations.ForeignKey;   @ForeignKey( name = "FK_PI_COMPANY_ID" ) @ManyToOne(targetEntity = Company.class, fetch = FetchType.EAGER) @JoinColumn(name = "COMPANY_ID", nullable = true) private Company company;

JSP Download EXCEL or PDF from Server

The following code snippet shows you how to download content i.e PDF and Excel files from Server. Since its a JSP page the output stream has been cleared so binary content will not be corrupted. Code can be converted to a servlet if required To change to other content formats for download just change setContentType e.g response.setContentType("image/png");