Friday, June 08, 2012

Hibernate joins with Non-Primary keys


Hibernate makes it a tad difficult to do joins on Non-Primary keys. But with a little annotation trick this can be sorted out.

So let's say there is a Parent Object
Parent (PK: id, foreign key : name)

And the Child Class:
Child(PK:id, parentName)
child.parentName maps to Parent.name
and there is a ManytoOne relationship between child and Parent.

So for the domain object mapping:

@Entity
@Table(name="Parent")
public class Parent {
 @Id
    @SequenceGenerator(name = "PARENT_ID_GENERATOR", sequenceName = "PARENT_ID_SEQ")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PARENT_ID_GENERATOR")
    @Column(name = "ID")
    private Long id;

    @OneToMany(mappedBy="parent")
    private  List<child> children;

}


So the parent is just like any other domain object, the key is to use the mappedBy with the OneToMany annotation.


For the child Class:

@Entity
@Table(name="Child")
public class Child{
@Id
    @SequenceGenerator(name = "CHILD_ID_GENERATOR", sequenceName = "CHILD_ID_SEQ")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CHILD_ID_GENERATOR")
    @Column(name = "ID")
    private Long id;

    @Column(name="parent_name")
    String parentName;

    @ManyToOne
    @JoinColumn(name="parent_name", referencedColumnName="name")
    Parent parent;

}

Notice how the joincolumn annotation is used. The name is the column in the child object and the referencedColumnName is the column in the parent.

That's it.
We have a join for OnetoMany Parent-&gt;Child relationship set up.</child></div>

Friday, November 11, 2011

Iframe and JAWS screen reader


Issue: Iframe was recognized by the screen reader but the content was not being read. This is extremely necessary for ADA compliance of websites.
Software: JS highslide, JAWS
Oddly enough the firefox plugin for emulating screen readers - fangs was reading the screen reader just fine and so was NVDA.

So here's the issue - when an inline frame is fired from a parent page, the focus is not automatically set to the frame, you have to manually set it. For regular frames, not using any plugins, using window.onload() function would work, but with the highslide plugin, that does not work, but the window loads inside the scope of the plugin and it just renders it later. So the onload function is actually called much before the frame is rendered. So here's the workaround.
In the iframe, make a dummy anchor tag, since anchor tags are easy to give focus to. like <a id="focus" href="#"></a>
On the parent frame, with the hs.expand call :
you will need to put this in the document.ready() function:

hs.Expander.prototype.onAfterExpand = function(sender){
            var body = sender.body;

            var iframe = window.frames[this.iframe.name],
               doc = iframe.document;
          
             doc.getElementById("focus").focus();
             doc.getElementById("focus").blur();
        }
So focus will set the focus on the a tag, which sometimes causes a cursor to appear. You could use the
style.cursor='not-allowed'; but I was having trouble with FF 8 on Windows 7. So I decided 
tto blur() the anchor tag.
A few quick notes:
1. display:none will not work - naturally focus cannot be set on an element that doesn't have a display.
2. I did add ARIA properties to the anchor tag to make sure it is read outloud and added the contents of the iframe as the alt attribute to the anchor tag:
tabindex ="-1" style="font-size:-1px" aria-live="assertive" aria-atomic="true"

Labels: , ,

Thursday, June 09, 2005

Hurray!!!

I got a call from amazon.com also today, this is the bestest thing to happen to me in the last few days. I am really excited and I look forward to any inputs from anyone.

Thanks...

Monday, June 06, 2005

First Thoughts

I have been fascinated with blogs for sometime now and I like the idea of people sharing their thoughts about anything and everything.

This space for anyone and everyone who is currently lookign out for jobs, I am a CSE graduate and I am looking for a job, I do have an offer but I am also interviewing with microsoft, dell . Any inputs from anyone would be really appreciated.

Have a great day!!!