Archive 2011

highlight results with javascript

September 20, 2011

highlight results with javascript (prototype required)

function highlightWordSearching(componentId, search){
    if(search && !search.blank()){
    search = search.replace(‘&’,’&’);
        var search_regexp = new RegExp(‘>([^]*)?<','ig');
        $(componentId).innerHTML = $(componentId).innerHTML.replace(search_regexp,’>$1$2$3<');
    }
}

OneToMany association : hql query returns no results

Problem: hql query retruns null or empty result while sql corresponding query returns some resultsets.
If the target hibernate Java Bean have an EmbeddedId be sure that the AttributeOverrides didn’t include a nullable column attribute.
If so remove these nullable columns attributes from embedded id and put them directly in the bean as Bean variable properties. And this will fix problem

Wrong Id definition

@Entity
@Table(name="WITR_MARIAGE", uniqueConstraints = @UniqueConstraint(columnNames={"CUSTOMER_ID", "WITR_HUSBAND_ID", "WITR_WIFE_ID"}) )
public class WitrMariage  implements java.io.Serializable {

    private WitrMariageId id;
    private WitrHusband witrHusband;
    private WitrWife witrWife;

    @EmbeddedId
    @AttributeOverrides( {
            @AttributeOverride(name="customerId", column=@Column(name="CUSTOMER_ID", nullable=false, precision=22, scale=0) ),
            @AttributeOverride(name="witrHusbandId", column=@Column(name="WITR_HUSBAND_ID", nullable=false, precision=22, scale=0) ),
            @AttributeOverride(name="witrWifeId", column=@Column(name="WITR_WIFE_ID", nullable=false, precision=22, scale=0) ),
            @AttributeOverride(name="sort", column=@Column(name="SORT", precision=22, scale=0) ) } )
    public WitrMariageId getId() {
        return this.id;
    }

    public void setId(WitrMariageId id) {
        this.id = id;
    }

    /*
     *   WitrHusband getter & setter
     *   WitrWife getter & setter
     */

}

Right Id definition

@Entity
@Table(name="WITR_MARIAGE", uniqueConstraints = @UniqueConstraint(columnNames={"CUSTOMER_ID", "WITR_HUSBAND_ID", "WITR_WIFE_ID"}) )
public class WitrMariage  implements java.io.Serializable {

    private WitrMariageId id;
    private WitrHusband witrHusband;
    private WitrWife witrWife;
    private long sort;

    @EmbeddedId
    @AttributeOverrides( {
            @AttributeOverride(name="customerId", column=@Column(name="CUSTOMER_ID", nullable=false, precision=22, scale=0) ),
            @AttributeOverride(name="witrHusbandId", column=@Column(name="WITR_HUSBAND_ID", nullable=false, precision=22, scale=0) ),
            @AttributeOverride(name="witrWifeId", column=@Column(name="WITR_WIFE_ID", nullable=false, precision=22, scale=0) ) } )
    public WitrMariageId getId() {
        return this.id;
    }

    public void setId(WitrMariageId id) {
        this.id = id;
    }

    /*
     *   WitrHusband getter & setter
     *   WitrWife getter & setter
     *   sort getter & setter
     */

}

find out oracle DB service name or SID

If I have system access to oracle DB, and want to find out the service name

> sqlplus system
password: XXXX
SQL> select sys_context(‘userenv’,’instance_name’) from dual;

output

SYS_CONTEXT(‘USERENV’,’INSTANCE_NAME’)
————————————————–
MY_INSTANCE_NAME

Now, to find out SID

SQL> select sys_context(‘userenv’,’sid’) from dual;

oracle: use tkprof


================================================= 19/06/2011
use tkprof
1. Login with oracle user
2. Sqlplus system/xxxx@SHEMA
3. alter system set sql_trace=true;
4. show parameter user_dump_dest;
4. Cd
5. tkprof xxxxx.trc /tmp/myAnalyse.out explain=user/pass@SHEMA sort=execpu
6. ne pas oublier : alter system set sql_trace=false;