<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Elegando</title>
	
	<link>http://elegando.jcg3.org</link>
	<description>elegant » being unusually effective and simple...</description>
	<lastBuildDate>Mon, 01 Mar 2010 20:17:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Elegando" /><feedburner:info uri="elegando" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Name Bench</title>
		<link>http://feedproxy.google.com/~r/Elegando/~3/DW9tY4pRL54/</link>
		<comments>http://elegando.jcg3.org/2010/03/name-bench/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 20:15:23 +0000</pubDate>
		<dc:creator>Jason G.</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://elegando.jcg3.org/2010/03/name-bench/</guid>
		<description><![CDATA[Is your internet intermittently slow? It might be your DNS provider&#8230; use Name Bench to see what the best DNS server for you is&#8230;]]></description>
			<content:encoded><![CDATA[<p>Is your internet intermittently slow? It might be your DNS provider&#8230; use <a href="http://code.google.com/p/namebench/">Name Bench</a> to see what the best DNS server for you is&#8230;</p>
<img src="http://feeds.feedburner.com/~r/Elegando/~4/DW9tY4pRL54" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://elegando.jcg3.org/2010/03/name-bench/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://elegando.jcg3.org/2010/03/name-bench/</feedburner:origLink></item>
		<item>
		<title>Calculate Age with SQL</title>
		<link>http://feedproxy.google.com/~r/Elegando/~3/kYxwr9Z7_wU/</link>
		<comments>http://elegando.jcg3.org/2010/03/calculate-age-with-sql/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 19:48:44 +0000</pubDate>
		<dc:creator>Jason G.</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://elegando.jcg3.org/2010/03/calculate-age-with-sql/</guid>
		<description><![CDATA[Here&#8217;s a quickie&#8230; Calculate someone&#8217;s age with SQL: select dob, floor(datediff(day, dob, getDate()) / 365.25) as age from personnel]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quickie&#8230;  Calculate someone&#8217;s age with SQL:</p>
<pre class="sql" name="code">
select dob,
    floor(datediff(day, dob, getDate()) / 365.25) as age
    from personnel
</pre>
<img src="http://feeds.feedburner.com/~r/Elegando/~4/kYxwr9Z7_wU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://elegando.jcg3.org/2010/03/calculate-age-with-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://elegando.jcg3.org/2010/03/calculate-age-with-sql/</feedburner:origLink></item>
		<item>
		<title>Aqua Data Studio 6.5 with Java 1.6</title>
		<link>http://feedproxy.google.com/~r/Elegando/~3/Y1wUYvp3k0w/</link>
		<comments>http://elegando.jcg3.org/2010/02/aqua-data-studio-6-5-with-java-1-6/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 02:25:34 +0000</pubDate>
		<dc:creator>Jason G.</dc:creator>
				<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://elegando.jcg3.org/2010/02/aqua-data-studio-6-5-with-java-1-6/</guid>
		<description><![CDATA[I use an older version (6.5) of Aqua Data Studio (an excellent tool), but it recently broke on the Mac when Java 1.6 came out. There is a quick fix for this, as the problem was a few classes moving outside of the JRE&#8217;s default libs. Download this file and put it in AquaDataStudio.app/Content/Resources/Java. Someone [...]]]></description>
			<content:encoded><![CDATA[<p>I use an older version (6.5) of <a href="http://www.aquafold.com/index.html">Aqua Data Studio</a> (an excellent tool), but it recently broke on the Mac when Java 1.6 came out. There is a quick fix for this, as the problem was a few classes moving outside of the JRE&#8217;s default libs.</p>
<p>Download <a href="/web/2010/02/aqua2.jar">this file</a> and put it in AquaDataStudio.app/Content/Resources/Java.</p>
<p>Someone else came up with this solution, but I have no idea of the original source.</p>
<img src="http://feeds.feedburner.com/~r/Elegando/~4/Y1wUYvp3k0w" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://elegando.jcg3.org/2010/02/aqua-data-studio-6-5-with-java-1-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://elegando.jcg3.org/2010/02/aqua-data-studio-6-5-with-java-1-6/</feedburner:origLink></item>
		<item>
		<title>Fix Offscreen Windows (Mac)</title>
		<link>http://feedproxy.google.com/~r/Elegando/~3/79JPbD0Napk/</link>
		<comments>http://elegando.jcg3.org/2010/02/fix-offscreen-windows-mac/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 01:06:21 +0000</pubDate>
		<dc:creator>Jason G.</dc:creator>
				<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://elegando.jcg3.org/2010/02/fix-offscreen-windows-mac/</guid>
		<description><![CDATA[I change screen resolutions on my Mac frequently &#8212; adding or removing external monitors, using external monitors of different sizes&#8230; Every once in a while a window is placed off screen or is too large to be resized within the screen available. Here&#8217;s a script to fix that&#8230; Launch the Apple Script Editor, and create [...]]]></description>
			<content:encoded><![CDATA[<p>I change screen resolutions on my Mac frequently &#8212; adding or removing external monitors, using external monitors of different sizes&#8230; Every once in a while a window is placed off screen or is too large to be resized within the screen available.</p>
<p>Here&#8217;s a script to fix that&#8230;</p>
<p><span id="more-145"></span></p>
<p>Launch the Apple Script Editor, and create a new script.  Enter the following in the script&#8230;</p>
<pre class="java" name="code">
-- Example list of processes to ignore: {"xGestures"} or {"xGestures", "OtherApp", ...}
property processesToIgnore : {"GeekTool"}

-- Get the size of the Display(s), only useful if there is one display
-- otherwise it will grab the total size of both displays
tell application "Finder"
	set _b to bounds of window of desktop
	set screen_width to item 3 of _b
	set screen_height to item 4 of _b
end tell

tell application "System Events"
	set allProcesses to application processes
	set _results to ""
	repeat with i from 1 to count allProcesses
		set doIt to 1
		repeat with z from 1 to count processesToIgnore
			if process i = process (item z of processesToIgnore) then
				set doIt to 0
			end if
		end repeat

		if doIt = 1 then
			tell process i
				repeat with x from 1 to (count windows)
					set winPos to position of window x
					set _x to item 1 of winPos
					set _y to item 2 of winPos
					set winPos to size of window x
					set _width to item 1 of winPos
					set _height to item 2 of winPos

					if (_x < 0 or _y < 0 or _x > screen_width or _y > screen_height) then
						set position of window x to {0, 22}
					end if
					if (_width > screen_width or _height > screen_height) then
						set size of window x to {screen_width - 100, screen_height - 100}
					end if
				end repeat

			end tell
		end if
	end repeat
end tell
</pre>
<p>Save the file, and then export as an application.  Do File &#8211;&gt; Save As, and change the File Format to be Application.  Once completed, you now have an executable (double-clickable) program that will run the script.</p>
<p>Note that I got this code from somewhere like <a href="http://www.leonamarant.com/2008/04/02/how-to-get-off-screen-windows-back-on-your-mac-os-x-v105/">this</a>, modified slightly for my use.</p>
<p>It&#8217;s also worth mentioning that someone else has already fixed this problem with a free app named <a href="http://www.macupdate.com/info.php/id/22709/forget-me-not">Forget-Me-Not</a>.</p>
<img src="http://feeds.feedburner.com/~r/Elegando/~4/79JPbD0Napk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://elegando.jcg3.org/2010/02/fix-offscreen-windows-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://elegando.jcg3.org/2010/02/fix-offscreen-windows-mac/</feedburner:origLink></item>
		<item>
		<title>Google Voice Dialer for iPhone</title>
		<link>http://feedproxy.google.com/~r/Elegando/~3/C1LGM7J7sXo/</link>
		<comments>http://elegando.jcg3.org/2009/12/google-voice-dialer-for-iphone/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 01:58:11 +0000</pubDate>
		<dc:creator>Jason G.</dc:creator>
				<category><![CDATA[Commentary]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://elegando.jcg3.org/2009/12/google-voice-dialer-for-iphone/</guid>
		<description><![CDATA[Got Google Voice? Want caller-id to show that number when you call someone instead of your iPhone&#8217;s actual mobile number? It appears there is no &#8220;app for that&#8221; as Apple, AT&#38;T and Google don&#8217;t want to play nice&#8230; Here&#8217;s a workaround&#8230; This is a more thorough explanation of a previous post. In lieu of an [...]]]></description>
			<content:encoded><![CDATA[<p>Got Google Voice? Want caller-id to show that number when you call someone instead of your iPhone&#8217;s actual mobile number? It appears there is no &#8220;app for that&#8221; as Apple, AT&amp;T and Google don&#8217;t want to play nice&#8230;</p>
<p>Here&#8217;s <a href="http://www.google.com/support/forum/p/voice/thread?tid=0b93243b9cd4288a&amp;hl=en">a workaround</a>&#8230;</p>
<p><span id="more-142"></span></p>
<blockquote>
<p>This is a more thorough explanation of a previous post. In lieu of an GV app, I figured out a quick and easy way to dial your most frequent contacts using no more than 2 clicks. All we&#8217;re doing is adding a bookmark to your iPhone home page that links to a contact&#8217;s unique URL in your GV address book. Ready?</p>
<p>  1. Load up the mobile GV site (https://www.google.com/voice/<wbr />m). It works fine in Firefox &#8212; it doesn&#8217;t redirect to the non-mobile version like other Google sites.</p>
<p>  2. Find your desired favorite in your contact list. Let&#8217;s use &#8220;Mom&#8221; for our example. Each contact has its own unique URL &#8211; something like https://www.google.com/voice/<wbr />m/contact/793238491687864. Copy this link to your clipboard.</p>
<p>  3. Use your favorite photo editing software to find the perfect headshot of mom. Crop it so it&#8217;s EXACTLY a square (I use Picasa).</p>
<p>  4. Resize mom&#8217;s picture so it&#8217;s 57 x 57, and save as a PNG to your desktop. (I used http://www.resize2mail.com/<wbr />advanced.php)</p>
<p>  5. Fire up http://webclipicons.info/ Upload your 57 x 57 PNG, give it the shortcut name &#8220;mom&#8221; and paste the GV unique contact URL from step 2 into the &#8220;shortcut URL&#8221; prompt. Put in your email address, and uncheck &#8220;make public.&#8221; Hit &#8220;create shortcut.&#8221;</p>
<p>  6. Check your iPhone email. You should receive a message with link &#8212; click on it. Safari should launch. Bookmark that page to your home screen. Your mom&#8217;s smiling face should appear along with your fart and other useless apps.</p>
<p>  7. When it&#8217;s time to call mom, click on her face. Her contact page in your GV account will load in Safari. You can then call or SMS any number that you have stored for her.</p>
</blockquote>
<p>via <a href="http://nyquil.org/archives/1226-Two-Work-arounds-for-Dialing-Google-Voice-on-iPhone.html">NyQuil.org</a>.</p>
<img src="http://feeds.feedburner.com/~r/Elegando/~4/C1LGM7J7sXo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://elegando.jcg3.org/2009/12/google-voice-dialer-for-iphone/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://elegando.jcg3.org/2009/12/google-voice-dialer-for-iphone/</feedburner:origLink></item>
		<item>
		<title>Mac Keyboard Hacks</title>
		<link>http://feedproxy.google.com/~r/Elegando/~3/qW5XVPAsFyg/</link>
		<comments>http://elegando.jcg3.org/2009/11/mac-keyboard-hacks/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 06:09:26 +0000</pubDate>
		<dc:creator>Jason G.</dc:creator>
				<category><![CDATA[Commentary]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://elegando.jcg3.org/2009/11/mac-keyboard-hacks/</guid>
		<description><![CDATA[Want to change your control key and caps lock key on your Mac (or just disable your caps lock key)? Use the built-in settings (System Preferences -&#62; Keyboard -&#62; Modifier Keys). Want to change your fn key? Use DoubleCommand.]]></description>
			<content:encoded><![CDATA[<p>Want to change your control key and caps lock key on your Mac (or just disable your caps lock key)? Use the built-in settings (System Preferences -&gt; Keyboard -&gt; Modifier Keys).</p>
<p>Want to change your fn key? Use <a href="http://doublecommand.sourceforge.net/features.html">DoubleCommand</a>.</p>
<img src="http://feeds.feedburner.com/~r/Elegando/~4/qW5XVPAsFyg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://elegando.jcg3.org/2009/11/mac-keyboard-hacks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://elegando.jcg3.org/2009/11/mac-keyboard-hacks/</feedburner:origLink></item>
		<item>
		<title>Firefox Gestures</title>
		<link>http://feedproxy.google.com/~r/Elegando/~3/WIlflfU7FcI/</link>
		<comments>http://elegando.jcg3.org/2009/11/firefox-gestures/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 04:50:42 +0000</pubDate>
		<dc:creator>Jason G.</dc:creator>
				<category><![CDATA[Commentary]]></category>
		<category><![CDATA[Firefox]]></category>

		<guid isPermaLink="false">http://elegando.jcg3.org/2009/11/firefox-gestures/</guid>
		<description><![CDATA[I was just playing around with some of the Firefox Gestures that are available on a Mac, and went looking for a list of commands that you can have the gestures trigger&#8230; since it wasn&#8217;t easy to find, here&#8217;s the scoop. First, go to Firefox&#8217;s about:config page&#8230; enter &#8220;about:config&#8221; in the location bar: Click past [...]]]></description>
			<content:encoded><![CDATA[<p>I was just playing around with some of the <a href="http://www.macosxhints.com/article.php?story=20090630172400412">Firefox Gestures that are available on a Mac</a>, and went looking for a list of commands that you can have the gestures trigger&#8230; since it wasn&#8217;t easy to find, here&#8217;s the scoop.</p>
<p><span id="more-140"></span>
<p>First, go to Firefox&#8217;s about:config page&#8230; enter &#8220;about:config&#8221; in the location bar:</p>
<p><img src="http://elegando.jcg3.org/web/2009/11/Screen-shot-2009-11-01-at-1.30.06-AM.png" width="155" height="34" alt="Screen shot 2009-11-01 at 1.30.06 AM.png" /></p>
<p>Click past the warning, and enter a filter-text of &#8220;gesture&#8221; to see the various multi-finger gestures and their commands.</p>
<p><img src="http://elegando.jcg3.org/wordpress/../web/2009/11/Screen-shot-2009-11-01-at-1.30.20-AM2.png" width="400" height="185" alt="Screen shot 2009-11-01 at 1.30.20 AM.png" rel="lightbox" /></p>
<p>Here are the possible values you can put in the Value, and thus which action you will trigger with the gesture.</p>
<ul>
<li>cmd_copy</li>
<li>cmd_cut</li>
<li>cmd_paste</li>
<li>cmd_selectAll</li>
<li>cmd_selectNone</li>
<li>cmd_copyLink</li>
<li>cmd_copyImageLocation</li>
<li>cmd_copyImageContents</li>
<li>cmd_scrollTop</li>
<li>cmd_scrollBottom</li>
<li>cmd_scrollPageUp</li>
<li>cmd_scrollPageDown</li>
<li>cmd_scrollLineUp</li>
<li>cmd_scrollLineDown</li>
<li>cmd_scrollLeft</li>
<li>cmd_scrollRight</li>
<li>cmd_selectCharPrevious</li>
<li>cmd_selectCharNext</li>
<li>cmd_wordPrevious</li>
<li>cmd_wordNext</li>
<li>cmd_selectWordPrevious</li>
<li>cmd_selectWordNext</li>
<li>cmd_beginLine</li>
<li>cmd_endLine</li>
<li>cmd_selectBeginLine</li>
<li>cmd_selectEndLine</li>
<li>cmd_selectLinePrevious</li>
<li>cmd_selectLineNext</li>
<li>cmd_selectPagePrevious</li>
<li>cmd_selectPageNext</li>
<li>cmd_selectMoveTop</li>
<li>cmd_selectMoveBottom</li>
</ul>
<ul>
<li>cmd_paste</li>
<li>cmd_pasteQuote</li>
<li>cmd_delete</li>
<li>cmd_deleteCharBackward</li>
<li>cmd_deleteCharForward</li>
<li>cmd_deleteWordBackward</li>
<li>cmd_deleteWordForward</li>
<li>cmd_deleteToBeginningOfLine</li>
<li>cmd_deleteToEndOfLine</li>
<li>cmd_delete</li>
<li>cmd_deleteCharBackward</li>
<li>cmd_deleteCharForward</li>
<li>cmd_deleteWordBackward</li>
<li>cmd_deleteWordForward</li>
<li>cmd_deleteToBeginningOfLine</li>
<li>cmd_deleteToEndOfLine</li>
<li>cmd_scrollTop</li>
<li>cmd_scrollBottom</li>
<li>cmd_moveTop</li>
<li>cmd_moveBottom</li>
<li>cmd_selectTop</li>
<li>cmd_selectBottom</li>
<li>cmd_lineNext</li>
<li>cmd_linePrevious</li>
<li>cmd_selectLineNext</li>
<li>cmd_selectLinePrevious</li>
<li>cmd_charPrevious</li>
<li>cmd_charNext</li>
<li>cmd_selectCharPrevious</li>
<li>cmd_selectCharNext</li>
<li>cmd_beginLine</li>
<li>cmd_endLine</li>
<li>cmd_selectBeginLine</li>
<li>cmd_selectEndLine</li>
<li>cmd_wordPrevious</li>
<li>cmd_wordNext</li>
<li>cmd_selectWordPrevious</li>
<li>cmd_selectWordNext</li>
<li>cmd_scrollPageUp</li>
<li>cmd_scrollPageDown</li>
<li>cmd_scrollLineUp</li>
<li>cmd_scrollLineDown</li>
<li>cmd_movePageUp</li>
<li>cmd_movePageDown</li>
<li>cmd_selectPageUp</li>
<li>cmd_selectPageDown</li>
</ul>
<p>The list is from <a href="http://www.mozilla.org/unix/customizing.html">Mozilla&#8217;s Website</a>.</p>
<p>You can also use these commands, which I figured out from trial and error:</p>
<ul>
<li>Browser:Home &#8211; takes you to your home page</li>
<li>Browser:PrevTab</li>
<li>Browser:NextTab</li>
<li>Browser:BackOrBackDuplicate &#8211; equivalent to back button</li>
<li>Browser:ForwardOrForwardDuplicate</li>
<li>Browser:Reload</li>
</ul>
<p>If you make a mistake, you can right-click on the setting and &#8220;reset&#8221; to the original configuration value.</p>
<p></p>
<img src="http://feeds.feedburner.com/~r/Elegando/~4/WIlflfU7FcI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://elegando.jcg3.org/2009/11/firefox-gestures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://elegando.jcg3.org/2009/11/firefox-gestures/</feedburner:origLink></item>
		<item>
		<title>RSS Feed Translation</title>
		<link>http://feedproxy.google.com/~r/Elegando/~3/1KcCdSLgkuk/</link>
		<comments>http://elegando.jcg3.org/2009/10/rss-feed-translation/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 15:01:09 +0000</pubDate>
		<dc:creator>Jason G.</dc:creator>
				<category><![CDATA[Commentary]]></category>
		<category><![CDATA[Mashup]]></category>

		<guid isPermaLink="false">http://elegando.jcg3.org/2009/10/rss-feed-translation/</guid>
		<description><![CDATA[Got an interesting RSS feed you wan to follow, but it&#8217;s in a different language? You can use the steps from this article by Rafe Needleman. The process includes using Yahoo Pipes to get the RSS feed, translate it, and then create new content output from that. Not horribly complicated, and quite a nice trick [...]]]></description>
			<content:encoded><![CDATA[<p>Got an interesting RSS feed you wan to follow, but it&#8217;s in a different language?</p>
<p>You can use the steps from <a href="http://news.cnet.com/8301-17939_109-9731147-2.html">this article by Rafe Needleman</a>. The process includes using Yahoo Pipes to get the RSS feed, translate it, and then create new content output from that. Not horribly complicated, and quite a nice trick to know about.</p>
<p>Note that Yahoo&#8217;s Pipes has moved the Babelfish translation into the deprecated list&#8230; not sure how long the functionality will continue to be supported.</p>
<img src="http://feeds.feedburner.com/~r/Elegando/~4/1KcCdSLgkuk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://elegando.jcg3.org/2009/10/rss-feed-translation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://elegando.jcg3.org/2009/10/rss-feed-translation/</feedburner:origLink></item>
		<item>
		<title>Hibernate @GeneratedValue</title>
		<link>http://feedproxy.google.com/~r/Elegando/~3/2KfhKwrWH14/</link>
		<comments>http://elegando.jcg3.org/2009/08/hibernate-generatedvalue/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 00:59:26 +0000</pubDate>
		<dc:creator>Jason G.</dc:creator>
				<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://elegando.jcg3.org/2009/08/hibernate-generatedvalue/</guid>
		<description><![CDATA[I spent a bit of time figuring out what all the annotations for a Hibernate/JPA @Id field should be, and wanted to document it. First up, with any entity, you need to add an @Id annotation to a field, I typically use a Long field. package test.model; import javax.persistence.*; import java.io.Serializable; @Entity @Table(name="test_table") public class [...]]]></description>
			<content:encoded><![CDATA[<p>I spent a bit of time figuring out what all the annotations for a Hibernate/JPA @Id field should be, and wanted to document it.</p>
<p>First up, with any entity, you need to add an @Id annotation to a field, I typically use a Long field.<span id="more-116"></span></p>
<pre class="java" name="code">package test.model;

import javax.persistence.*;
import java.io.Serializable;

@Entity
@Table(name="test_table")
public class TestTable implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name="test_table_id")
    private Long id;

    // getters &amp; setters
}</pre>
<p>All is good and well, until we want to persist new TestTable objects.  Now we need a @GeneratedValue annotation&#8230;  you can use a variety of strategies: GenerationType.AUTO, IDENTITY, SEQUENCE, or TABLE.  Auto will have Hibernate guess at which version is best for your database type (e.g., a sequence for Oracle, an identity for MS SQL).</p>
<p>One requirement I typically have is that the application code and resultant data structure be database agnostic, and more specifically, have the same index strategy despite different databases.  So, we can define a strategy that will be implemented the same regardless of database type.</p>
<p>For a TABLE generation strategy, you can simply specify the strategy.  This will result in a table &#8220;hibernate_sequences&#8221; and a caching size of 10 (I think).</p>
<pre class="java" name="code">@Id
@Column(name="test_table_id")
@GeneratedValue(strategy=GenerationType.TABLE)
private Long id;</pre>
<p>This is fine, but Hibernate is actually caching the index number for you, and only writing out the index to table every 10 or so inserts.  We will want to change that (despite the performance hit) if we have anything that may not be using Hibernate to access these indexes.</p>
<p>The following will do the same as above (hibernate_sequences table), but flush the index out on every increment of the index.  The &#8220;generatorName&#8221; below is just an arbitrary name that pairs the two annotations.</p>
<pre class="java" name="code">@Id
@Column(name="test_table_id")
@GeneratedValue(strategy=GenerationType.TABLE, generator="generatorName")
@TableGenerator(name="generatorName", allocationSize=1)
private Long id;</pre>
<p>Want more control?  It&#8217;s available&#8230;  Here we&#8217;ll specify the table to put the sequences into, in case there was an existing table strategy used in some other project that you&#8217;d like to work with.</p>
<pre class="java" name="code">@Id
@Column(name="test_table_id")
@GeneratedValue(strategy=GenerationType.TABLE, generator="generatorName")
@TableGenerator(name="generatorName", table="TableID",
				pkColumnName="tablename", // TableID.TableName (value = table_name, test_table, etc.)
				valueColumnName="id", // TableID.ID (value = 1,2,3,etc.)
				allocationSize=1 // flush every 1 insert
)
private Long id;</pre>
<p>We can also use a custom coded IdentifierGenerator when using Hibernate.  The class MyIdGenerator extends IdentifierGenerator in the example below.  I also chose to implement Configurable so I could pass the table name into the generator.</p>
<pre class="java" name="code">// new imports
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
// annotations for ID field
@Id
@Column(name="test_table_id")
@GeneratedValue(generator="UniqueIdGenerator")
@GenericGenerator(name="UniqueIdGenerator", strategy="test.util.MyIdGenerator",
	parameters = { @Parameter(name="tableName", value="test_table") } )
private Long id;</pre>
<p>And here is the ID generator&#8230;</p>
<pre class="java" name="code">package test.util;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.id.Configurable;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.type.Type;

public class MyIdGenerator implements IdentifierGenerator, Configurable {
	private String tableName;

    public void configure( Type arg0, Properties props, Dialect arg2 )
            throws MappingException {
        setTableName( props.getProperty( "tableName" ) );
    }

    public Serializable generate( SessionImplementor session, Object arg1 )
            throws HibernateException {
        // we want to open a new connection / transaction
        Connection conn = session.getBatcher().openConnection();

        Serializable id = null;
        try {
            id = new IdGenerator().generate( conn, tableName );
        } catch( SQLException e ) {
            throw new HibernateException( e );
        } finally {
            session.getBatcher().closeConnection( conn );
        }
        return id;
    }

    // getter &#038; setter for the configurable parameters
    public String getTableName() {
        return tableName;
    }
    public void setTableName( String tableName ) {
    	this.tableName = tableName;
    }
}</pre>
<img src="http://feeds.feedburner.com/~r/Elegando/~4/2KfhKwrWH14" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://elegando.jcg3.org/2009/08/hibernate-generatedvalue/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://elegando.jcg3.org/2009/08/hibernate-generatedvalue/</feedburner:origLink></item>
		<item>
		<title>Domain Move</title>
		<link>http://feedproxy.google.com/~r/Elegando/~3/_abi-JPDPbA/</link>
		<comments>http://elegando.jcg3.org/2009/07/domain-move/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 02:54:07 +0000</pubDate>
		<dc:creator>Jason G.</dc:creator>
				<category><![CDATA[Commentary]]></category>

		<guid isPermaLink="false">http://elegando.jcg3.org/2009/07/domain-move/</guid>
		<description><![CDATA[FYI, I will be retiring the www.elegando.com domain when it expires later this year. All content will now be at elegando.jcg3.org instead. Please update your RSS feed readers as appropriate&#8230;]]></description>
			<content:encoded><![CDATA[<p>FYI, I will be retiring the <a href="http://elegando.jcg3.org/">www.elegando.com</a> domain when it expires later this year. All content will now be at <a href="http://elegando.jcg3.org/">elegando.jcg3.org</a> instead. Please update your RSS feed readers as appropriate&#8230;</p>
<img src="http://feeds.feedburner.com/~r/Elegando/~4/_abi-JPDPbA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://elegando.jcg3.org/2009/07/domain-move/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://elegando.jcg3.org/2009/07/domain-move/</feedburner:origLink></item>
	</channel>
</rss>
