I found these useful tips on how to customize Firefox and get it faster.
Now, when I have time I need to test if they're working because in the meantime I switched to Chrome despite my lifelong appreciation for the Fox. This is to tell you how unusable it has become.
Thursday, May 17, 2012
Monday, May 14, 2012
No Cascade Delete on a Collection Relationship
I had the following relationship in a UserAnswer, the answer(s) a user can give to a question in a survey:
I wanted to propagate all persistence operations to the collection except DELETE. I didn't want an Answer to be deleted when all UserAnswers were removed.
This is how it worked for me:
@ManyToMany(targetEntity=Answer.class, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
@JoinTable(name="userAnswer_answers",
joinColumns=@JoinColumn(name="userAnswer_fk"),
inverseJoinColumns=@JoinColumn(name="answer_fk"))
@Sort(type = SortType.COMPARATOR, comparator = AnswerPositionComparator.class)
public SortedSet
return selectedAnswers;
}
If you don't use CascadeType.ALL, Hibernate doesn't cascade the save of an entity's Collection properties when using the PERSIST annotation. You have to explicitly use the org.hibernate.annotations.CascadeType.SAVE_UPDATE annotation.
Source here.
Friday, May 11, 2012
Eclipse Code Templates
If you'd like to have your own text additions to a new file upon its creation, you can customize the way it is created with code templates.
Go to Window --> Properties --> Java --> Code Styles --> Code Templates.
You can customize comments and code components in this way at Eclipse level or project level.
Go to Window --> Properties --> Java --> Code Styles --> Code Templates.
You can customize comments and code components in this way at Eclipse level or project level.
Labels:
code template,
customize new file,
eclipse
Monday, January 30, 2012
hbm2ddl SchemaExport: You have an error in your SQL syntax near type=InnoDB
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=InnoDB'
I used to create my MySQL DBs with ant and everything was working. Now, moving to maven and hbm2ddl I get this error.
After some searching it comes out that it's a problem of incompatibility between the MySQL Java connector (5.1) and the MySQL version (5.5) where type InnoDB was dropped and replaced with engine.
The solution is to change the MySQL dialect from org.hibernate.dialect.MySQLInnoDBDialect to org.hibernate.dialect.MySQL5InnoDBDialect.
Places where this generally occurs are hibernate.cfg.xml and hibernate.properties.
Tested on MySQL 5.5.22
Wednesday, November 09, 2011
Maven + Subversion Enabled Eclipse Java Project
Updated - Apr 2013
What I want for my Eclipse projects is to be Java projects, allow content revisions with Subversion and be managed by Maven.
This is what I need to do.
Eclipse version: Eclipse Juno
Subversion plugin: Subversive
Maven plugin: m2eclipse (m2e)
Support for Subversion and Maven is now integrated into Eclipse.
You can further configure Maven under Window --> Preferences --> Maven. In particular you can add an external Maven installation and change the location of the repository which defaults to the user's personal repository and not the global one.
What I want for my Eclipse projects is to be Java projects, allow content revisions with Subversion and be managed by Maven.
This is what I need to do.
Eclipse version: Eclipse Juno
Subversion plugin: Subversive
Maven plugin: m2eclipse (m2e)
Support for Subversion and Maven is now integrated into Eclipse.
- Choose Help --> Install new software --> Work with: Juno - http://download.eclipse.org/releases/juno.
- Expand collaboration and check the m2eclipse and Subversive packages. Install all required components.
- Add the Polarion update site: http://community.polarion.com/projects/subversive/download/eclipse/2.0/juno-site/ (see step 1 for details) and install the Subversive SVN Connectors and a connector of your choice (I use SVNKit 1.7.4)
- Create a new project (Checkout Maven projects from SCM). Choose svn as SCM URL and type the URL. If svn does not appear in the list, check the global configuration under Window --> Preferences --> Team --> SVN --> SVN Connector. The connector you just installed must appear on that list.
- Once the project has been created, you might have a Java-Maven project only. If that's the case, to connect it to the SVN repository, right click on the project's name, choose Team --> Share --> SVN and follow the instructions to conncet your project to the SVN source.
You can further configure Maven under Window --> Preferences --> Maven. In particular you can add an external Maven installation and change the location of the repository which defaults to the user's personal repository and not the global one.
Monday, October 24, 2011
Liferay: Error Registering Portlets
I got a problem when trying to undeploy a portlet on Liferay the standard way: removing the unzipped WAR in Tomcat's webapps/ dir and the cached information.
08:48:56,725 ERROR [HotDeployUtil:112] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering portlets for MyPortlet
It seemd like the portlet was somehow still in the page for Liferay and the message saying the portlet needed to be removed from the page did not show any buttons to do that. After a while I didn't have the message anymore but only an error page.
Some googling brought me on a page in the Liferay forum where they suggested to remove the portlet-api-2.0.jar from the lib/ directory of the WAR and redeploy it:
> zip -d MyPortlet.war /WEB-INF/lib/portlet-api-2.0.jar
It actually worked. Don't ask me why.
08:48:56,725 ERROR [HotDeployUtil:112] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering portlets for MyPortlet
It seemd like the portlet was somehow still in the page for Liferay and the message saying the portlet needed to be removed from the page did not show any buttons to do that. After a while I didn't have the message anymore but only an error page.
Some googling brought me on a page in the Liferay forum where they suggested to remove the portlet-api-2.0.jar from the lib/ directory of the WAR and redeploy it:
> zip -d MyPortlet.war /WEB-INF/lib/portlet-api-2.0.jar
It actually worked. Don't ask me why.
Monday, August 08, 2011
Batch Resize on Linux
Install imagemagick.
Now you can use mogrify.
Example: to resize to half the original size all the JPGs in a directory (keeping the aspect ratio of course):
> mogrify -resize 50% *.jpg
More here.
Now you can use mogrify.
Example: to resize to half the original size all the JPGs in a directory (keeping the aspect ratio of course):
> mogrify -resize 50% *.jpg
More here.
Labels:
graphics,
imagemagick,
linux,
mogrify,
resize
Eclipse Startup - Crash on Fedora 15
For some obscure reason, the Fedora 15-packaged Eclipse doesn't include JSP syntax highlighting and I could find no easy way to add it (conflicting dependencies prevent that). So I resorted to the original TAR-GZ distribution. The problem there is with the OpenJDK. My Eclipse simply crashes on startup.
What you need to do is tell Eclipse to use Sun's JDK.
Open the eclipse.ini and add the path to the Java executable:
-vm
/opt/java/jdk1.6.0/bin/java
right before the -vmargs option.
More here.
[UPDATE] - Oh, the reason for the crash is not openJDK. It's a bug in Fedora. To circumvent it do the following:
What you need to do is tell Eclipse to use Sun's JDK.
Open the eclipse.ini and add the path to the Java executable:
-vm
/opt/java/jdk1.6.0/bin/java
right before the -vmargs option.
More here.
[UPDATE] - Oh, the reason for the crash is not openJDK. It's a bug in Fedora. To circumvent it do the following:
- In Gnome3 the webkit library name changed to libwebkitgtk so you need to create one missing symbolic link: ln -s /usr/lib/libwebkitgtk-1.0.so.0 /usr/lib/libwebkit-1.0.so.2
- Add -Dorg.eclipse.swt.browser.UseWebKitGTK=true to the -vmargs options in eclipse.ini
Friday, July 01, 2011
Extracting Audio from Video or Stream
From AVI or other video formats:
> ffmpeg -i file_name.avi -ab 128 -ar 44100 file_name.mp3
From an online stream:
> ffmpeg -i URL_address -ab 128 -ar 44100 file_name.mp3
> man ffmpeg
> ffmpeg -i file_name.avi -ab 128 -ar 44100 file_name.mp3
From an online stream:
> ffmpeg -i URL_address -ab 128 -ar 44100 file_name.mp3
> man ffmpeg
Wednesday, June 15, 2011
Fedora 15: Old and New Alt-Tab Behavior
As of Fedora 14 (Gnome 2.32) the behavior of Alt-Tab was to cycle through all the windows of all the open applications in a virtual workspace.
Gnome 3 shipping with Fedora 15 behaves differently and probably more efficiently (time will tell.)
Alt-Tab now cycles through all open applications in all virtual workspaces. All the windows of an application are shown when that application is the selected one. You can move the mouse over one window and select it but you can't just use the keyboard to do that.
If you want to cycle through all the windows of the active (selected) application you need to use Alt-~ (or the button above Tab.)
Gnome 3 shipping with Fedora 15 behaves differently and probably more efficiently (time will tell.)
Alt-Tab now cycles through all open applications in all virtual workspaces. All the windows of an application are shown when that application is the selected one. You can move the mouse over one window and select it but you can't just use the keyboard to do that.
If you want to cycle through all the windows of the active (selected) application you need to use Alt-~ (or the button above Tab.)
Fedora 15: Add Back Shutdown Option
Gnome 3 by default won't show the shutdown button. To see it click on your name on the top bar and press Alt. The Suspend option will turn into Power off.
If you don't want to perform this extra step (updated after kind comment):
If you don't want to perform this extra step (updated after kind comment):
- Install: yum install gnome-shell-extensions-alternative-status-menu.
- Type Alt-F2 then gnome-tweak-tool
- Go to Shell Extensions --> Alternative Status Menu Extension and switch it to on
- Type Alt-F2 then r and enter (reloads the Gnome shell.)
- You're set! You have gained the Hibernate and Power off options now.
Fedora 15: Add Back Window Buttons
UPDATED on May 9, 2020
Gnome 3 default behavior suppresses all window buttons but the Close. If you want them back:
> gsettings set org.gnome.desktop.wm.preferences button-layout ":minimize,maximize,close"
or use: gnome-tweak-tool.
References:
Wednesday, December 22, 2010
Eclipse Error: "Import Cannot Be Resolved"
The imported class is there but Eclipse won't see it.
Try: Project --> Clean
Try: Project --> Clean
Thursday, November 25, 2010
Creating a SVN Repository
Create the repository
> svnadmin create svnrepo
> gedit svnrepo/conf/svnserve.conf
Enable the following lines:
anon-access = none
auth-access = write
password-db = passwd
> gedit svnrepo/conf/passwd
Edit/add user
Create project directory:
> svn -m "Your comment" mkdir file:///data/svnrepo/sample-project
> svn -m "Your comment" mkdir file:///data/svnrepo/sample-project/trunk
> svn -m "Your comment" mkdir file:///data/svnrepo/sample-project/branches
> svn -m "Your comment" mkdir file:///data/svnrepo/sample-project/tags
Import the project:
> svn -m "Your comment" import /path-to-source/sample-project file:///path-to-svnrepo/svnrepo/sample-project/trunk
Prepare work location:
> mkdir sampleProject
> cd sampleProject
Local check out trunk of project (without the folder itself):
> svn co file:///data/svnrepo/sample-project/trunk/ .
Remote check out (using SVN + SSH protocols):
> svn co svn+ssh://user@host/path-to-svnrepo/svnrepo/sample-project/trunk/ .
Create user and group svn:
> useradd svn
Add group svn to your groups.
Change ownership of all files in svnrepo/db to svn:
> chown -r svn:svn *
Add write permissions to all files in svnrepo/db.
> svnadmin create svnrepo
> gedit svnrepo/conf/svnserve.conf
Enable the following lines:
anon-access = none
auth-access = write
password-db = passwd
> gedit svnrepo/conf/passwd
Edit/add user
Create project directory:
> svn -m "Your comment" mkdir file:///data/svnrepo/sample-project
> svn -m "Your comment" mkdir file:///data/svnrepo/sample-project/trunk
> svn -m "Your comment" mkdir file:///data/svnrepo/sample-project/branches
> svn -m "Your comment" mkdir file:///data/svnrepo/sample-project/tags
Import the project:
> svn -m "Your comment" import /path-to-source/sample-project file:///path-to-svnrepo/svnrepo/sample-project/trunk
Prepare work location:
> mkdir sampleProject
> cd sampleProject
Local check out trunk of project (without the folder itself):
> svn co file:///data/svnrepo/sample-project/trunk/ .
Remote check out (using SVN + SSH protocols):
> svn co svn+ssh://user@host/path-to-svnrepo/svnrepo/sample-project/trunk/ .
Create user and group svn:
> useradd svn
Add group svn to your groups.
Change ownership of all files in svnrepo/db to svn:
> chown -r svn:svn *
Add write permissions to all files in svnrepo/db.
Monday, November 22, 2010
Microphone Not Working in Fedora 14
If your microphone is not working on your new installation, just try this. It worked for me:
- Go to System --> Preferences --> Sound
- Select the input tab
- Switch from the existing configured microphone (probably microphone 1) to another one (microphone 2)
- Close the application and everything should work ;-)
Friday, November 19, 2010
Spring Property Editor for an Enumeration with Localized Names
Problem statement:
while the setAsText() method does not:
This is because Spring implicitly uses the enumeration name for the value of your tag, not the translated name.
E.g. If you have a select tag, this is what Spring does for you:
It makes sense, of course...
- You use a property editor when you bind a nested Enumeration field of a form backing object.
- You have localized names for the values.
@Override
public String getAsText() {
if(getValue() == null) {
return null;
}
SurveyStatus status = (SurveyStatus)getValue();
return status.getTranslatedName();
}
while the setAsText() method does not:
@Override
public void setAsText(String surveyStatusStr) {
if (logger.isDebugEnabled()) {
logger.debug("Read string [" + surveyStatusStr + "] for the survey status field");
}
SurveyStatus status = null;
if (surveyStatusStr.compareTo(SurveyStatus.ACTIVE.toString()) == 0) {
status = SurveyStatus.ACTIVE;
}
else if (surveyStatusStr.compareTo(SurveyStatus.INACTIVE.toString()) == 0) {
status = SurveyStatus.INACTIVE;
}
setValue(status);
}
This is because Spring implicitly uses the enumeration name for the value of your tag, not the translated name.
E.g. If you have a select tag, this is what Spring does for you:
<option value="ACTIVE" ... >
It makes sense, of course...
Labels:
binding,
property editor,
spring framework
Wednesday, September 15, 2010
Grep Selected Files
You can use find and grep to search for a particular string (string_pattern) in a selection of files:
> find <dir> -name "<file_find_pattern>" -exec grep -H -n '<string_pattern>' {} \;
> find <dir> -name "<file_find_pattern>" -exec grep -H -n '<string_pattern>' {} \;
Thursday, September 09, 2010
Spring Open View In Session Pattern For Portlets
I needed to implement the Open Session In View pattern for a portlet using Spring (3 with annotations) and Hibernate.
This pattern allows lazily loaded objects to have access to the Hibernate Session for the entire processing of the render request despite the original transaction (associated to the portlet request) already being completed.
I.e. If you have One To Many associations, this allows you to load the Many side of the association in the same thread of the request where you loaded the One side.
What I needed to do is:
Add a WebRequestHandlerInterceptorAdapter interceptor wrapping the stantard OpenSessionInViewInterceptor to applicationContext.xml:
then add it to the DefaultAnnotationHandlerMapping in yourPortlet-portlet.xml:
This pattern allows lazily loaded objects to have access to the Hibernate Session for the entire processing of the render request despite the original transaction (associated to the portlet request) already being completed.
I.e. If you have One To Many associations, this allows you to load the Many side of the association in the same thread of the request where you loaded the One side.
What I needed to do is:
Add a WebRequestHandlerInterceptorAdapter interceptor wrapping the stantard OpenSessionInViewInterceptor to applicationContext.xml:
<bean name="openSessionInViewInterceptor"
class="org.springframework.web.portlet.handler.WebRequestHandlerInterceptorAdapter">
<constructor-arg>
<bean class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</constructor-arg>
</bean>
then add it to the DefaultAnnotationHandlerMapping in yourPortlet-portlet.xml:
<bean id="annotationMapper"
class="org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="10" />
<property name="interceptors">
<list>
<ref bean="openSessionInViewInterceptor"/>
</list>
</property>
</bean>
Labels:
annotations,
hibernate,
open session in view,
spring framework
Wednesday, May 12, 2010
Fedora: Receiving Files Over a Bluetooth Connection
This post refers to receiving files from a phone to a computer over a Bluetooth connection.
Please refer to the official Fedora documentation for installation and initial configuration:
Then you have to enable the bluetooth file sharing service.
If you can't find the link to the application in Applications --> System Tools, then create the link yourself or launch the following command manually:
> gnome-file-share-properties&
Enable Receive Files over Bluetooth.
Go to your phone and send the file to your computer.
Please refer to the official Fedora documentation for installation and initial configuration:
Then you have to enable the bluetooth file sharing service.
If you can't find the link to the application in Applications --> System Tools, then create the link yourself or launch the following command manually:
> gnome-file-share-properties&
Enable Receive Files over Bluetooth.
Go to your phone and send the file to your computer.
Friday, April 16, 2010
Hibernate ManyToOne Association With Annotations
It took me a while to get rid of a:
ERROR org.hibernate.util.JDBCExceptionReporter -
Unknown column 'applicatio0_.domain_domainID' in 'field list'
on a simple many-to-one association.
I had an Application object with a Domain field where many Applications could have the same Domain (standard many-to-one association).
The annotations on the field were:
Class Domain started with:
Hibernate couldn't correctly map the domain ID until I added the JoinColumn annotation:
which in my opinion could be inferred from class Domain:
but it wasn't.
Always use JoinColumn.
ERROR org.hibernate.util.JDBCExceptionReporter -
Unknown column 'applicatio0_.domain_domainID' in 'field list'
on a simple many-to-one association.
I had an Application object with a Domain field where many Applications could have the same Domain (standard many-to-one association).
The annotations on the field were:
@ManyToOne(cascade = CascadeType.ALL)
public Domain getDomain() {
return domain;
}
Class Domain started with:
@Entity
@Table(name="domain")
public class Domain implements Serializable {
// DB name: domainID
private Long id;
private String name;
Hibernate couldn't correctly map the domain ID until I added the JoinColumn annotation:
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name="domainID")
public Domain getDomain() {
return domain;
}
which in my opinion could be inferred from class Domain:
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "domainID", unique = true,
updatable = false, nullable = false)
public Long getId() {
return this.id;
}
but it wasn't.
Always use JoinColumn.
Subscribe to:
Posts (Atom)