What is convenience method in java?

i generate hibernate pojos + hybernate mapping + dao. in dao class i have some doubt in coding please clear.
package org.triology.blog.hibernate;
import org.triology.blog.GenericDAO;
import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.List;
import java.util.Map;
import org.hibernate.Criteria;
import org.hibernate.FlushMode;
import org.hibernate.Query;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Example;
* Generated at Wed Jul 30 16:57:35 IST 2008
* @author Salto-db Generator v1.0.16 / Pojos + Hibernate mapping + Generic DAO
* @see http://www.hibernate.org/328.html
public abstract class AbstractHibernateDAO<T, ID extends Serializable> implements GenericDAO<T, ID> {
private Session session;
private Class<T> persistentClass;
public AbstractHibernateDAO() {
this.persistentClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
public void setSession(Session session) {
this.session = session;
protected Session getSession() {
if (session == null)
session = HibernateUtil.getSessionFactory().getCurrentSession();
return session;
public Class<T> getPersistentClass() {
return persistentClass;
@SuppressWarnings("unchecked")
public T getById(ID id) {
return (T) getSession().get(getPersistentClass(), id);
@SuppressWarnings("unchecked")
public T getById(ID id, boolean lock) {
if (lock) {
return (T) getSession().get(getPersistentClass(), id,
LockMode.UPGRADE);
} else
return getById(id);
@SuppressWarnings("unchecked")
public T loadById(ID id) {
return (T) getSession().load(getPersistentClass(), id);
public void save(T entity) {
getSession().save(entity);
public void update(T entity) {
getSession().update(entity);
public void saveOrUpdate(T entity) {
getSession().saveOrUpdate(entity);
public void delete(T entity) {
getSession().delete(entity);
public void deleteById(ID id)      {
getSession().delete(loadById(id));
@SuppressWarnings("unchecked")
public List<T> findAll() {
return findByCriteria();
* Use this inside subclasses as a convenience method.
@SuppressWarnings("unchecked")
protected List<T> findByCriteria(Criterion... criterion) {
Criteria crit = getSession().createCriteria(getPersistentClass());
for (Criterion c : criterion) {
crit.add(c);
return crit.list();
* Find by criteria.
@SuppressWarnings("unchecked")
public List<T> findByCriteria(Map criterias) {
Criteria criteria = getSession().createCriteria(getPersistentClass());
criteria.add(Restrictions.allEq(criterias));
return criteria.list();
* This method will execute an HQL query and return the number of affected entities.
protected int executeQuery(String query, String namedParams[],     Object params[]) {
Query q = getSession().createQuery(query);
if (namedParams != null) {
for (int i = 0; i < namedParams.length; i++) {
q.setParameter(namedParams, params[i]);
return q.executeUpdate();
protected int executeQuery(String query) {
return executeQuery(query, null, null);
* This method will execute a Named HQL query and return the number of affected entities.
protected int executeNamedQuery(String namedQuery, String namedParams[],     Object params[]) {
Query q = getSession().getNamedQuery(namedQuery);
if (namedParams != null) {
for (int i = 0; i < namedParams.length; i++) {
q.setParameter(namedParams[i], params[i]);
return q.executeUpdate();
protected int executeNamedQuery(String namedQuery) {
return executeNamedQuery(namedQuery, null, null);
@SuppressWarnings("unchecked")
public List<T> findByExample(T exampleInstance, String[] excludeProperty) {
Criteria crit = getSession().createCriteria(getPersistentClass());
Example example = Example.create(exampleInstance).excludeZeroes().enableLike().ignoreCase();
for (String exclude : excludeProperty) {
example.excludeProperty(exclude);
crit.add(example);
return crit.list();
in above class my doubt is
* Use this inside subclasses as a convenience method.
@SuppressWarnings("unchecked")
protected List<T> findByCriteria(Criterion... criterion) {
Criteria crit = getSession().createCriteria(getPersistentClass());
for (Criterion c : criterion) {
crit.add(c);
return crit.list();
why we pass findByCriteria parameter end with three dots (Criterian...)

When you post code, please use code tags as described in [Formatting tips|http://forum.java.sun.com/help.jspa?sec=formatting] on the message entry page. It makes it much easier to read.
Also try to strip the example code down to just what you want to show.
why we pass findByCriteria parameter end with three dots (Criterian...)
varargs
Please do not [cross post|http://forums.sun.com/thread.jspa?threadID=5319163]. Finding out that someone else has already answered this question in a different thread is very irritating, and will put people off answering you future queries.
Edited by: mlk on 31-Jul-2008 09:14

Similar Messages

  • What are the methods called while navigating from one applet to another one

    Hi All,
    Could any one brief me about "When you navigate from one applet to another what are the methods called ?".
    Thanks in advance.
    Best Regards,
    N.Madhusudhanan.

    http://forum.java.sun.com/thread.jsp?forum=421&thread=426771&tstart=0&trange=100

  • Error(23,19): method getName(java.lang.String) not found in class javax.swi

    Hi , when i try to run my program, i keep getting the error msg:
    Error(23,19): method getName(java.lang.String) not found in class javax.swing.JTextField
    I have checked the java API and it inherits from the awt.Component class and should be accessible via the jtextfield.
    I have tried the following:
    trying to initailise the JTextField at the start.
    Using getName works if i use it within the loop after setting the name.
    Does anybody know what i am doing wrong please?
    public class clsMember extends JPanel implements ActionListener {
        private JButton jbtnLog;
        private String surname;
        private JTextField txtItem;
        public clsMember() {
            super(new SpringLayout());
            makeInterface();
            surname = txtItem.getName("Surname").toString();
    private void makeInterface() {
         //code omitted
               for (int i = 0; i < numpairs; i++) {
                JLabel l = new JLabel(strLabels, JLabel.LEADING);
    this.add(l);
    //if the array item is salutation create a combobox
    if (strLabels[i] == "Salutation") {
    jcomSalutation = new JComboBox(strSalutation);
    jcomSalutation.setSelectedIndex(0);
    this.add(jcomSalutation);
    } else {
    txtItem = new JTextField(10);
    l.setLabelFor(txtItem);
    txtItem.setName(strLabels[i].replaceAll(" ", "")); //this is where the label is set and if i do a system.out it shows fine. getName works here too.
    this.add(txtItem);
    //code omitted

    If i have a loop that creates the jtextfields such as
                    txtItem = new JTextField(10);
                    l.setLabelFor(txtItem);
                    txtItem.setName(strLabels.replaceAll(" ", ""));
    this.add(txtItem);How is it then possible to assign to a string the value of a *specific jtextfield*. Lets say that one of these JTextfields has the name surname.
    How is it possible for me to writeString surname = surnamejtextfield.getText();                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • What is wrong in this java code?

    Can someone please tell me what is wrong in this java code?
    /* The program is intended to start animating text at the click of a button, pause it at another click and resume at the next click. It should continue like this */
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    public class TextAnime implements Runnable
    JFrame frame;
    boolean flag;
    Thread animeThread;
    JLabel label;
    String[] textArray;
    public TextAnime()
    flag = false;
    animeThread = new Thread(this);
    frame = new JFrame("Animate Text");
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    frame.setLayout(gbl);
    JButton button = new JButton("Start");
    label = new JLabel("Stopped");
    textArray = new String[5];
    String textArray1[] = {"Programmer", "SportsMan", "Genius", "Friend", "Knowledgable"};
    for(int ctr = 0; ctr<5 ; ctr++)
    textArray[ctr] = textArray1[ctr];
    gbc.weightx = 1;
    gbc.gridx = 0;
    gbl.setConstraints(button,gbc);
    frame.getContentPane().add(button);
    ButList bl = new ButList();
    button.addActionListener(bl);
    gbc.gridx = 1;
    gbl.setConstraints(label,gbc);
    frame.getContentPane().add(label);
    frame.setSize(200,150);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setVisible(true);
    public class ButList implements ActionListener
    public void actionPerformed(ActionEvent evt)
    if(flag == false)
    flag = true;
    animeStart();
    else
    flag = false;
    //animeStop();
    public synchronized void animeStart()
    animeThread.start();
    Thread newThread;
    newThread = Thread.currentThread();
    newThread.notify();
    public void animeStop()
    animeThread.interrupt();
    public void run()
    int i = 0;
    try
    while(i == i)
    if(i==5)
    i=0;
    label.setText(textArray);
    animeThread.sleep(1000);
    i++;
    if (flag == false)
    animeThread.wait();
    catch(InterruptedException ie)
    label.setText("Stopped");
    public static void main(String args[])
    TextAnime ta = new TextAnime();
    Please tell me if this can be written in a more simpler manner. Also please correct this code. I am tired after trying many times.

    When I fix your error, compile and run it, I get this exception:
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalMonitorStateException
         at java.lang.Object.notify(Native Method)
         at cruft.TextAnime.animeStart(TextAnime.java:81)
         at cruft.TextAnime$ButList.actionPerformed(TextAnime.java:63)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
         at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
         at java.awt.Component.processMouseEvent(Component.java:6038)
         at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
         at java.awt.Component.processEvent(Component.java:5803)
         at java.awt.Container.processEvent(Container.java:2058)
         at java.awt.Component.dispatchEventImpl(Component.java:4410)
         at java.awt.Container.dispatchEventImpl(Container.java:2116)
         at java.awt.Component.dispatchEvent(Component.java:4240)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
         at java.awt.Container.dispatchEventImpl(Container.java:2102)
         at java.awt.Window.dispatchEventImpl(Window.java:2429)
         at java.awt.Component.dispatchEvent(Component.java:4240)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
         at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
    %

  • Puzzled by the redefinition of the methods in java.util.Set

    Hi all,
    I don't understand why those methods in java.util.Set redefined since their counterparts have alrealdy been defined in java.util.Collection and java.util.Set extends java.util.Collection. I agree to redefine boolean add(Object o) because its contract has been modified, but what about the rest like
    size() and iterator() ?
    Thanks.

    Hi all,
    I don't understand why those methods in
    in java.util.Set redefined since their counterparts
    have alrealdy been defined in java.util.Collection
    and java.util.Set extends java.util.Collection. I
    agree to redefine boolean add(Object o) because its
    contract has been modified, but what about the rest
    like
    size() and iterator() ?Completeness's sake?
    ~Cheers

  • Error(400,8): method include(java.lang.String, boolean) not found in class

    I have uploaded my Application which was running fine in other IDE to jdev 10.1.3, when i compile the follwing error error in jsp page.
    Error(400,8): method include(java.lang.String, boolean) not found in class javax.servlet.jsp.PageContext
    My jsp code where error is shown is
    <jsp:include page="querySections/generation.jsp" flush="true">
                                            <jsp:param name="TSN" value="<%=strParamValue[1]%>"/>
                                            <jsp:param name="SectionID" value="<%=String.valueOf(lngSectionID)%>"/>
                                       </jsp:include>
    pl help me in solving this its urgent...
    Thanks & Regards
    Lakshmi

    Hi,
    code snippet looks okay and is identical with what JDeveloper generates.
    Frank

  • What is the method name?

    Hello:
    I understood that i have to override the paintComponent method.
    But my question is that, what is the method declaration by which shall i set the background image? where image name is winter.jpg
    I will be highly grateful to u if u kindly give me the proper answer.

    The answer was already given to you in your other post.
    icewalker2g gave you this site http://www.jguru.com/faq/view.jsp?EID=9691
    The code:
    import javax.swing.*;
    import java.awt.*;
    public class BackgroundSample {
      public static void main(String args[]) {
        JFrame frame = new JFrame("Background Example");
        final ImageIcon imageIcon = new ImageIcon("draft.gif"); // <--- change this image to your image
        JTextArea textArea = new JTextArea() {
          Image image = imageIcon.getImage();
          Image grayImage = GrayFilter.createDisabledImage(image);
          {setOpaque(false);}  // instance initializer
          public void paintComponent (Graphics g) {
            g.drawImage(grayImage, 0, 0, this);
            super.paintComponent(g);
        JScrollPane scrollPane = new JScrollPane(textArea);
        Container content = frame.getContentPane();
        content.add(scrollPane, BorderLayout.CENTER);
        frame.setDefaultCloseOperation(3);
        frame.setSize(250, 250);
        frame.setVisible(true);
    }In the future please read your post and don't multipost and crosspost.

  • What is Markable Interface in JAVA

    What is Markable Interface in JAVA need explanation

    Markable interface in one which does not contain any
    method or member declaration.
    Eg: Serializable, Observable etc...terminology aside, I don't think "not containing any methods" is enough to call something a marker interface. is EventListener a marker interface? I don't think so, I think of it as a supertype for all other event listeners in the JDK

  • What is the Method to get record from DB as Date fornat??

    Halo, i want to know what is the method to get the data from database which is store it in date format.
    Previously, i am using the getDate() to get the data together with the while (rs.next() ) method after using the "select" statement to get the data from data base.
    Here is the example when i retrieve record from database:
    java.util.Date date1 = new java.util.Date();
    String getRecord = "SELECT * FROM employee "
    ResultSet rs = db. execSQL(getRecord);
    while(rs.next() ){
    String name = rs.getString("name");
    date1 = rs.getDate("date");
    }notes: method getDate() had deprecated since JDK version 1.1.
    So, i need to know what is the method to get the date record??
    Thank you.....

    Halo, ...Yeah, Halo! Love that game...
    Um, use getDate(). ResultSet.getDate() is not deprecated. If you think so, then you better go reread the API docs, cuz you're reading the wrong ones.

  • What caan this method do

    what does this methode do and how can i use it
    StringBuilder insert(int offset, char c)
      what does the int offset stand for
    tahnksin advance

    there is automatically-generated documentationthat's
    supposed to answer questions like that :
    [url=http://java.sun.com/j2se/1.5.0/docs/api/index.htm
    l]JavaDocs
    if the op follows the link at the bottom of my post
    it will display the javadoc for the StringBuilder
    class.
    however, the index is always a good place to start
    and it makes a good bookmark
    when it's become your homepage, it'll be time you realized you are a GEEEEEEEEEEEEEEEEEK
    >
    i think i'll read your other helpful link also, I've
    seen it referenced before.I'm re-reading it right now... goddam' good reading that is... :)

  • What a static method cannot be overriden?

    Parent class
    public class Person {
       private String surname;
       private String firstName;
       private String secondName;
       public Person(String surname,
                     String firstName,
                     String secondName) {
            this.surname = surname;
            this.firstName = firstName;
            this.secondName = secondName;
       public static void test() { ; }
    }Sub class
    public class Member extends Person {
         private int membershipNumber;
                     public Member(String surname,
                      String firstName,
                      String secondName,
                      int membershipNumber) {
              super(surname, firstName, secondName);
              this.membershipNumber = membershipNumber;
         public String toString() {
              return membershipNumber + "-" + super.toString();
         public void test() { System.out.println("test") ; }
    }And I got compilation error :
    H:\java\wshp2>javac *.java
    Member.java:20: test() in Member cannot override test() in Person; overridden me
    thod is static
    public void test() { System.out.println("test") ; }
    ^
    1 error
    H:\java\wshp2>pause
    Since static method and the overriding method are going to be used differently (in different ways), why it can't be allowed?
    Static method is a Class method whereas the overriding method is a instance method, they can be distinguished. What is the reason behind this?
    Please enlighten me.
    Thanks

    Are final method bound at compile-time?Basically when a method is "bound" cannot be used to explain the behaviour of methods in Java. It's the other way around. It's the characteristics of a method that decides when it can be "bound". But that's an implementation issue and not part of the language itself.
    A static method cannot be overriden because it's not meant to be overridden. It's against the semantics of a static method to be overridden. Also if you declare a method final you decide that you don't want it to be overriden. In both cases, based on this non-overriding restriction, the compiler can decide when to "bind" the method.

  • Calling C++ method from Java program on Linux

    I'm trying to get set up to call a C++ method from a Java app on a SUSE Linux box. I follow the steps of the "Hello World" baby example in Beth Stearns's tutorial, "Integrating Native Code and Java Programs", but I get the following error message:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: /users/dmizell/testIF/libhello.so: /users/dmizell/testIF/libhello.so: invalid ELF header (Possible cause: endianness mismatch)
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1778)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1703)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1028)
    at HelloWorld.<clinit>(HW.java:7)
    at Main.main(Main.java:5)
    Any idea what I might be doing wrong?
    thanks
    David

    Your library is compiled in a way which is incompatible with the VM you are using.
    Note that there is a JNI forum.

  • Calling javascript method from java

    Hi this is sri,
    I have one doubt on Java Applets "how to call the javascript method from java Applet".Can u give me the complete sample code for one program(both java applet file and html file also)because i can easily understand the programming flow.
    Thanks ,
    Srilekha.

    It's an extremely important skill to learn how to search the web. Not only will it increase your research and development talents, it will also save you from asking questions that have already been answered numerous times before. By doing a little research before you ask a question, you'll show that you're willing to work and learn without needing to have your hand held the entire time; a quality that is seemingly rare but much appreciated by the volunteers who are willing to help you.
    If you've done the research, found nothing useful, and decide to post your question, it's a great idea to tell us that you've already searched (and what methodologies you used to do your research). That way, we don't refer you back to something you've already seen.
    To get you started, here's a link...
    http://www.google.com/search?q=call+java+from+javascript

  • HT5625 if i have multiple apple IDS and i would like to delete all of them except the one I wish to continue using what is the method

    In case I have multiple Apple Ids and I want to delete all of them except one , what is the method to be followed.??
    Or is it that there is no scope for deletion and the Ids are just disabled

    Sorry, Apple ID's cannot be deleted or merged. All you can do is stop using an Apple ID.

  • How to call the java method in java script function in a portal application

    Hi Friends,
    I am developing one application where i need to fetch the data from KM content and displaying it on the screen in regular interval. I wrote one method in JSPdynpage for fetching data from KM content now I need to call that java method in java script function.
    java method(IComponentRequest request)
    //Coode for fetching the KM content
    function()
    <b>//Need to call the java method</b>
    setTimeout(function, 5000);//setting the time interval for this function
    <<htmlb display code>>
    If anybody can help me in calling the java method in java script function that will be very helpful for me.
    Thanks in advance,
    Sandeep Bonam

    Hi,
    Pls see if the following links could help.
    http://www.rgagnon.com/javadetails/java-0170.html
    http://www-128.ibm.com/developerworks/library/wa-resc/?dwzone=web
    Regards

Maybe you are looking for

  • New iTunes update, iPod no longer shows up in iTunes

    Got a update request from iTunes today and accepted the upgrade for iTunes and QuickTime.  I ignored the warning from Microsoft that this was not approved for XP (stupid, but I doubted that Apple would trash my connection).  After the install, I no l

  • Duplex Printing in Reports 3.0

    I am trying to print a report on both sides of the paper, using Reports 3.0. I have no problem doing this with Reports 2.5. The printer properties have been set properly, so it must be the report. Any ideas would be greatly appreciated. thanx Some de

  • Exporting originals naming problem.

    In exporting original files, I chose to have the originals named with the preset of filename+date+time.  But all of the new file names show 2016 as the year instead of 2015, which is when they were taken and what shows up as the information included

  • File on DVD disappear

    At one point I had a DVD burner on my machine. However, after I would burn the DVD and go back to test the files (paranoid), filenames and files would randomly start to disappear. I've since purchased another DVD burner think the last was faulty and

  • Mail: load 25 more messages???

    Hello, Im not sure as to why I keep getting this message in the mail app on the iPhone. I'm usinga pop account and all the settings are fine except when I check my mail. There is a message that says ; load 25more messages? Has anyone else experienced