Archive for the 'java' Category

16
Sep
11

useful swing border

This could be useful to have a graphical view of how much space a component is taking on the screen.


class JComponent
  def create_border
    setBorder(BorderFactory.createLineBorder(Color.black))
  end
end

13
Aug
11

android set color from xml file


Here’s how you set a color, defined in your colors.xml, from code:


textView.setTextColor(getResources().getColor(R.color.red));

26
Feb
11

Hibernate exceptions 0.04 Exception in thread “main” org.hibernate.SessionException: Session was already closed


I received this exception:

Exception in thread "main" org.hibernate.SessionException: Session was already closed

A solution is presented in this post. Another solution would be to modify your code to use this:

HibernateUtil.getSessionFactory().openSession();

the first time, instead of :

HibernateUtil.getSessionFactory().getCurrentSession();

The above solution was found on this stackoverflow answer

26
Feb
11

Hibernate exceptions 0.03 Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: javax/persistence/JoinTable


If you receive this error, Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: javax/persistence/JoinTable, make sure you have the ejb3-persistence.jar added to your classpath.

26
Feb
11

Hibernate-Mapping package attribute


The package attribute in <hibernate-mapping package=”some.package”> is used so that you can write:

<hibernate-mapping package=”h1″>

<class name=”Whatever” table=”WHATEVER”>
<id name=”id” column=”WHATEVER_ID”>
<generator class=”native”/>
</id>
</class>

</hibernate-mapping>

instead of:

<hibernate-mapping>

<class name=”h1.Whatever” table=”WHATEVER”>
<id name=”id” column=”WHATEVER_ID”>
<generator class=”native”/>
</id>
</class>

</hibernate-mapping>

26
Feb
11

Hibernate exceptions 0.02 Exception in thread “main” org.hibernate.HibernateException: No CurrentSessionContext configured!


This will appear if you didn’t define the current_session_context_class property. One possible way of fixing this would be adding:

<property name=”current_session_context_class”>thread</property>

to your hibernate.cfg.xml

03
Jun
10

how to find the content-length of a URL using URLConnection/HttpUrlConnection


Here’s how:


URLConnection a = new URL("http://insertWebsiteAddressHere").openConnection();
System.out.println(a.getContentLength());




Blog Stats

  • 223,713 hits