⧠Oh, my gosh...
ããããnativeQueryã®çµæããããã³ã°ã§ããã®ãï¼
調ã¹ãéãã§ã¯ã
⧠ä¸è¨ãµã¤ãæ§ãåèã«ãªãããã§ãã
JPAã§nativeQueryã®ã¯ã¨ãªã®çµæããããã³ã°ããããã©...
ãã ãçµå±ã®ã¨ãããSQLæ¯ã«ã¨ã³ãã£ãã£ãä½ã£ã¦ãããªãã¨æãã®ã§ãnativeQueryã®çµæãã¨ã³ãã£ãã£ãDTOã«å¤æããã®ãæåã§ãããããå¾ãªããã¨ã
ã©ããããã¨ãã¨è¨ãã¨ãæ»ãå¤ã¯åãã§ãSQLã®æ¡ä»¶ãå¾®å¦ã«ç°ãªãå ´åã«ãSqlResultSetMappingã¨NamedNativeQueryã使ãæ¹æ³ã ã¨ã10åã®SQLæãããã¨10åã®ã¨ã³ãã£ãã£ãç¨æããªãã¨ãããªããªãã¾ãã¨ã
ããã§ãã¯ã¨ãªã®æ»ãå¤ãList<Object[]>ã«ãªãã®ã許容ãã¦ãæåã§ãããã³ã°ããã¨ããé¸æè¢ãããã®ããªã¨ã
PostgreSQLã§ä»¥ä¸ã®ãããªãã¼ãã«ãç¨æããã¨ãã¦ã
create table public.shikoku_ohenro ( id serial not null , name_fudasyo character varying(20) not null , kana_name_fudasyo character varying(50) not null , rome_name_fudasyo character varying(50) not null , name_temple character varying(20) not null , kana_name_temple character varying(50) not null , rome_name_temple character varying(50) not null , prefectures_id integer not null , created timestamp(6) with time zone default CURRENT_TIMESTAMP , updated timestamp(6) with time zone , is_deleted boolean default false , primary key (id) );
create table public.prefectures ( id integer not null , name_prefecture character varying(20) not null , kana_name_prefecture character varying(50) not null , rome_name_prefecture character varying(50) not null , name_prefectural_capital character varying(20) not null , kana_name_prefectural_capital character varying(50) not null , rome_name_prefectural_capital character varying(50) not null , area_id integer not null , created timestamp(6) with time zone default CURRENT_TIMESTAMP , updated timestamp(6) with time zone , is_deleted boolean default false , primary key (id) );
ãã¼ã¿ãINSERTãã¦ããã
-- é½éåºçãã¼ã¿ INSERT INTO prefectures (id, name_prefecture, kana_name_prefecture, rome_name_prefecture, name_prefectural_capital, kana_name_prefectural_capital, rome_name_prefectural_capital, area_id) VALUES(1,'åæµ·é', 'ã»ã£ããã©ã', 'hokkaido','æå¹', 'ãã£ã½ã', 'sapporo', 1) ,(2,'é森ç', 'ãããããã', 'aomoriken','é森', 'ãããã', 'aomori', 2) ,(3,'岩æç', 'ããã¦ãã', 'iwateken','ç岡', 'ãããã', 'morioka', 2) ,(4,'å®®åç', 'ã¿ãããã', 'miyagiken','ä»å°', 'ããã ã', 'sendai', 2) ,(5,'ç§ç°ç', 'ããããã', 'akitaken','ç§ç°', 'ããã', 'akita', 2) ,(6,'山形ç', 'ãã¾ãããã', 'yamagataken','山形', 'ãã¾ãã', 'yamagata', 2) ,(7,'ç¦å³¶ç', 'ãµããã¾ãã', 'fukushimaken','ç¦å³¶', 'ãµããã¾', 'fukushima', 2) ,(8,'è¨åç', 'ãã°ãããã', 'ibarakiken','æ°´æ¸', 'ã¿ã¨', 'mito', 3) ,(9,'æ æ¨ç', 'ã¨ã¡ããã', 'tochigiken','å®é½å®®', 'ãã¤ã®ã¿ã', 'utsunomiya', 3) ,(10,'群馬ç', 'ããã¾ãã', 'gunmaken','åæ©', 'ã¾ãã°ã', 'maebashi', 3) ,(11,'å¼çç', 'ãããã¾ãã', 'saitamaken','ãããã¾', 'ãããã¾', 'saitama', 3) ,(12,'åèç', 'ã¡ã°ãã', 'chibaken','åè', 'ã¡ã°', 'chiba', 3) ,(13,'æ±äº¬é½', 'ã¨ããããã¨', 'tokyoto','æ°å®¿', 'ãããã ã', 'shinjyuku', 3) ,(14,'ç¥å¥å·ç', 'ããªãããã', 'kanagawaken','横æµ', 'ããã¯ã¾', 'yokohama', 3) ,(15,'æ°æ½ç', 'ã«ããããã', 'nigataken','æ°æ½', 'ã«ããã', 'niigata', 4) ,(16,'å¯å±±ç', 'ã¨ãã¾ãã', 'toyamaken','å¯å±±', 'ã¨ãã¾', 'toyama', 4) ,(17,'ç³å·ç', 'ãããããã', 'ishikawaken','éæ²¢', 'ããªãã', 'kanazawa', 4) ,(18,'ç¦äºç', 'ãµãããã', 'fukuiken','ç¦äº', 'ãµãã', 'fukui', 4) ,(19,'山梨ç', 'ãã¾ãªããã', 'yamanashiken','ç²åº', 'ãããµ', 'koufu', 4) ,(20,'é·éç', 'ãªãã®ãã', 'naganoken','é·é', 'ãªãã®', 'nagano', 4) ,(21,'å²éç', 'ããµãã', 'gifuken','å²é', 'ããµ', 'gifu', 4) ,(22,'é岡ç', 'ãããããã', 'shizuokaken','é岡', 'ãããã', 'shizuoka', 4) ,(23,'æç¥ç', 'ããã¡ãã', 'aichiken','åå¤å±', 'ãªãã', 'nagoya', 4) ,(24,'ä¸éç', 'ã¿ããã', 'mieken','æ´¥', 'ã¤', 'tsu', 5) ,(25,'æ»è³ç', 'ãããã', 'shigaken','大津', 'ããã¤', 'ootsu', 5) ,(26,'京é½åº', 'ãããã¨ãµ', 'kyotofu','京é½', 'ãããã¨', 'kyoto', 5) ,(27,'大éªåº', 'ãããããµ', 'oosakafu','大éª', 'ãããã', 'oosaka', 5) ,(28,'å µåº«ç', 'ã²ããããã', 'hyogoken','ç¥æ¸', 'ããã¹', 'koube', 5) ,(29,'å¥è¯ç', 'ãªããã', 'naraken','å¥è¯', 'ãªã', 'nara', 5) ,(30,'åæå±±ç', 'ãããã¾ãã', 'wakayamaken','åæå±±', 'ãããã¾', 'wakayama', 5) ,(31,'é³¥åç', 'ã¨ã£ã¨ããã', 'tottoriken','é³¥å', 'ã¨ã£ã¨ã', 'tottori', 6) ,(32,'å³¶æ ¹ç', 'ãã¾ããã', 'shimaneken','æ¾æ±', 'ã¾ã¤ã', 'matsue', 6) ,(33,'岡山ç', 'ãããã¾ãã', 'okayamaken','岡山', 'ãããã¾', 'okayama', 6) ,(34,'åºå³¶ç', 'ã²ããã¾ãã', 'hiroshimaken','åºå³¶', 'ã²ããã¾', 'hiroshima', 6) ,(35,'å±±å£ç', 'ãã¾ãã¡ãã', 'yamaguchiken','å±±å£', 'ãã¾ãã¡', 'yamaguchi', 6) ,(36,'徳島ç', 'ã¨ããã¾ãã', 'tokushimaken','徳島', 'ã¨ããã¾', 'tokushima', 6) ,(37,'é¦å·ç', 'ããããã', 'kagawaken','é«æ¾', 'ããã¾ã¤', 'takamatsu', 6) ,(38,'æåªç', 'ãã²ããã', 'ehimeken','æ¾å±±', 'ã¾ã¤ãã¾', 'matsuyama', 6) ,(39,'é«ç¥ç', 'ããã¡ãã', 'kouchiken','é«ç¥', 'ããã¡', 'kouchi', 6) ,(40,'ç¦å²¡ç', 'ãµããããã', 'fukuokaken','ç¦å²¡', 'ãµããã', 'fukuoka', 7) ,(41,'ä½è³ç', 'ãããã', 'sagaken','ä½è³', 'ãã', 'saga', 7) ,(42,'é·å´ç', 'ãªããããã', 'nagasakiken','é·å´', 'ãªããã', 'nagasaki', 7) ,(43,'çæ¬ç', 'ãã¾ãã¨ãã', 'kumamotoken','çæ¬', 'ãã¾ãã¨', 'kumamoto', 7) ,(44,'大åç', 'ãããããã', 'ooitaken','大å', 'ãããã', 'ooita', 7) ,(45,'å®®å´ç', 'ã¿ããããã', 'miyazakiken','å®®å´', 'ã¿ããã', 'miyazaki', 7) ,(46,'鹿å 島ç', 'ãããã¾ãã', 'kagoshimaken','鹿å 島', 'ãããã¾', 'kagoshima', 7) ,(47,'æ²ç¸ç', 'ãããªããã', 'okinawaken','é£è¦', 'ãªã¯', 'naha', 7);
-- ãéè·¯ãã¼ã¿ INSERT INTO shikoku_ohenro (id, name_fudasyo, kana_name_fudasyo, rome_name_fudasyo, name_temple, kana_name_temple, rome_name_temple, prefectures_id) VALUES(1, '第1çªææ','ã ããã¡ã°ããµã ãã', 'daiichibanfudasyo', 'é山寺', 'ãããããã', 'ryozenji', 36) ,(2, '第2çªææ','ã ãã«ã°ããµã ãã', 'dainibanfudasyo', '極楽寺', 'ããããã', 'gokurakuji', 36) ,(3, '第3çªææ','ã ãããã°ããµã ãã', 'daisanbanfudasyo', 'éæ³å¯º', 'ããããã', 'konsenji', 36) ,(4, '第4çªææ','ã ãããã°ããµã ãã', 'daiyonbanfudasyo', '大æ¥å¯º', 'ã ãã«ã¡ã', 'dainichiji', 36) ,(5, '第5çªææ','ã ããã°ããµã ãã', 'daiigobanfudasyo', 'å°èµå¯º', 'ãããã', 'jizouji', 36) ,(6, '第6çªææ','ã ãããã°ããµã ãã', 'dairokubanfudasyo','å®æ¥½å¯º', 'ããããã', 'anrakuji', 36) ,(7, '第7çªææ','ã ããªãªã°ããµã ãã', 'dainanabanfudasyo','å楽寺', 'ãã ãããã', 'jyurakuji', 36) ,(8, '第8çªææ','ã ãã¯ã¡ã°ããµã ãã', 'daihachibanfudasyo','ç谷寺', 'ãã¾ã ã«ã ', 'kumadaniji', 36) ,(9, '第9çªææ','ã ããã ãã°ããµã ãã', 'daikyubanfudasyo','æ³è¼ªå¯º', 'ã»ãããã', 'hourinji', 36) ,(10,'第10çªææ','ã ããã ãã°ããµã ãã', 'daijyubanbanfudasyo','å幡寺', 'ããã¯ãã', 'kiriharadai', 36) ,(11,'第11çªææ','ã ããã ããã¡ã°ããµã ãã', 'daijyuichibanfudasyo', 'è¤äºå¯º', 'ãµããã§ã', 'fujiidera', 36) ,(12,'第12çªææ','ã ããã ãã«ã°ããµã ãã', 'daijyuuibanfudasyo','ç¼å±±å¯º', 'ãããããã', 'syouzanji', 36) ,(13,'第13çªææ','ã ããã ãããã°ããµã ãã', 'daijyusanbanfudasyo','大æ¥å¯º', 'ã ãã«ã¡ã', 'dainichiji', 36) ,(14,'第14çªææ','ã ããã ãããã°ããµã ãã', 'daijyuyonbanfudasyo','常楽寺', 'ãããããã', 'jyourakuji', 36) ,(15,'第15çªææ','ã ããã ããã°ããµã ãã', 'daijyugobanfudasyo','å½å寺', 'ããã¶ãã', 'kokubunji', 36) ,(16,'第16çªææ','ã ããã ãããã°ããµã ãã', 'daijyurokubanfudasyo','観é³å¯º', 'ããããã', 'kanonji', 36) ,(17,'第17çªææ','ã ããã ããªãªã°ããµã ãã', 'daijyunanabanfudasyo','äºæ¸å¯º', 'ãã©ã', 'idoji', 36) ,(18,'第18çªææ','ã ããã ãã¯ã¡ã°ããµã ãã', 'daijyuhachibanfudasyo','æ©å±±å¯º', 'ããããã', 'onzanji', 36) ,(19,'第19çªææ','ã ããã ããã ãã°ããµã ãã', 'daijyukyubanfudasyo','ç«æ±å¯º', 'ãã¤ãã', 'ritsuenji', 36) ,(20,'第20çªææ','ã ãã«ãã ãã°ããµã ãã', 'dainijyubanfudasyo','鶴æ寺', ' ããããã', 'kakurinji', 36) ,(21,'第21çªææ','ã ãã«ãã ããã¡ã°ããµã ãã', 'dainijyuichibanfudasyo','太é¾å¯º', 'ãããã ãã', 'tairyuji', 36) ,(22,'第22çªææ','ã ãã«ãã ãã«ã°ããµã ãã', 'dainijyunibanfudasyo', 'å¹³ç寺', 'ã³ããã©ãã', 'byoudouji', 36) ,(23,'第23çªææ','ã ãã«ãã ãããã°ããµã ãã', 'dainijyusanbanfudasyo','è¬ç寺', 'ããããã', 'yakuouji', 36) ,(24,'第24çªææ','ã ãã«ãã ãããã°ããµã ãã', 'dainijyuyonbanfudasyo', 'æ御å´å¯º', 'ã»ã¤ã¿ããã', 'hotsumisakiji', 39) ,(25,'第25çªææ','ã ãã«ãã ããã°ããµã ãã', 'dainijyugobanfudasyo', 'æ´¥ç §å¯º', 'ãããããã', 'shinsyouji', 39) ,(26,'第26çªææ','ã ãã«ãã ãããã°ããµã ãã', 'dainijyurokubanfudasyo','éåé 寺', 'ããããã¡ããã', 'kongoutyouji', 39) ,(27,'第27çªææ','ã ãã«ãã ããªãªã°ããµã ãã', 'dainijyunanabanfudasyo','ç¥å³°å¯º', 'ããã®ã¿ãã', 'kounomineji', 39) ,(28,'第28çªææ','ã ãã«ãã ãã¯ã¡ã°ããµã ãã', 'dainijyuhachibanfudasyo','大æ¥å¯º', 'ã ãã«ã¡ã', 'dainichiji', 39) ,(29,'第29çªææ','ã ãã«ãã ããã ãã°ããµã ãã', 'dainijyukyubanfudasyo','å½å寺', 'ããã¶ãã', 'kokubunji', 39) ,(30,'第30çªææ','ã ããããã ãã°ããµã ãã', 'daisanjyubanfudasyo','å楽寺', 'ããããã', 'zenrakuji', 39) ,(31,'第31çªææ','ã ããããã ããã¡ã°ããµã ãã', 'daisanjyuichibanfudasyo','竹æ寺', 'ã¡ãããã', 'chikurinji', 39) ,(32,'第32çªææ','ã ããããã ãã«ã°ããµã ãã', 'daisanjyunibanfudasyo','ç¦ å¸«å³°å¯º', 'ãããã¶ã', 'zenjibuji', 39) ,(33,'第33çªææ','ã ããããã ãããã°ããµã ãã', 'daisanjyusanbanfudasyo','éªè¹å¯º', 'ãã£ããã', 'sekkeiji', 39) ,(34,'第34çªææ','ã ããããã ãããã°ããµã ãã', 'daisanjyuyonbanfudasyo','種é寺', 'ããã¾ã', 'tamaneji', 39) ,(35,'第35çªææ','ã ããããã ããã°ããµã ãã', 'daisanjyugobanfudasyo','æ¸ æ»å¯º', 'ããããã', 'kiyotakiji', 39) ,(36,'第36çªææ','ã ããããã ãããã°ããµã ãã', 'daisanjyurokubanfudasyo','éé¾å¯º', 'ããããã ãã', 'syouryuji', 39) ,(37,'第37çªææ','ã ããããã ããªãªã°ããµã ãã', 'daisanjyunanabanfudasyo','岩æ¬å¯º', 'ãããã¨ã', 'iwamotoji', 39) ,(38,'第38çªææ','ã ããããã ãã¯ã¡ã°ããµã ãã', 'daisanjyuhachibanfudasyo','éåç¦å¯º', 'ãããããµãã', 'kongoufukuji', 39) ,(39,'第39çªææ','ã ããããã ããã ãã°ããµã ãã', 'daisanjyukyubanfudasyo','延å 寺', 'ããããã', 'enkouji', 39) ,(40,'第40çªææ','ã ããããã ãã°ããµã ãã', 'daiyonjyubanfudasyo','観èªå¨å¯º', 'ãããããã', 'kanjizaiji', 38) ,(41,'第41çªææ','ã ããããã ããã¡ã°ããµã ãã', 'daiyonjyuichibanfudasyo','é¾å 寺', 'ãã ãããã', 'ryukouji', 38) ,(42,'第42çªææ','ã ããããã ãã«ã°ããµã ãã', 'daiyonjyunibanfudasyo','ä½æ¨å¯º', 'ã¶ã¤ããã', 'butsumokuji', 38) ,(43,'第43çªææ','ã ããããã ãããã°ããµã ãã', 'daiyonjyusanbanfudasyo','æç³å¯º', 'ããããã', 'ageishiji', 38) ,(44,'第44çªææ','ã ããããã ãããã°ããµã ãã', 'daiyonjyuyonbanfudasyo','大å®å¯º', 'ã ãã»ãã', 'daihouji', 38) ,(45,'第45çªææ','ã ããããã ããã°ããµã ãã', 'daiyonjyugobanfudasyo','岩å±å¯º', 'ãããã', 'iwayaji', 38) ,(46,'第46çªææ','ã ããããã ãããã°ããµã ãã', 'daiyonjyurokubanfudasyo','æµç ç寺', 'ãããããã', 'jyoururiji', 38) ,(47,'第47çªææ','ã ããããã ããªãªã°ããµã ãã', 'daiyonjyunanabanfudasyo','å «å寺', 'ãããã', 'yasakaji', 38) ,(48,'第48çªææ','ã ããããã ãã¯ã¡ã°ããµã ãã', 'daiyonjyuhachibanfudasyo','西æ寺', 'ããããã', 'sairinji', 38) ,(49,'第49çªææ','ã ããããã ããã ãã°ããµã ãã', 'daiyonjyukyubanfudasyo','æµå寺', 'ãããã©ã', 'jyoudoji', 38) ,(50,'第50çªææ','ã ãããã ãã°ããµã ãã', 'daigojyubanbanfudasyo','ç¹å¤å¯º', 'ã¯ããã', 'hantaji', 38) ,(51,'第51çªææ','ã ãããã ããã¡ã°ããµã ãã', 'daigojyuichibanfudasyo','ç³æ寺', 'ããã¦ã', 'ishiteji', 38) ,(52,'第52çªææ','ã ãããã ãã«ã°ããµã ãã', 'daigojyunibanfudasyo','太山寺', 'ããããã', 'taisaiji', 38) ,(53,'第53çªææ','ã ãããã ãããã°ããµã ãã', 'daigojyusanbanfudasyo','åæ寺', 'ããã¿ããã', 'enmyouji', 38) ,(54,'第54çªææ','ã ãããã ãããã°ããµã ãã', 'daigojyuyonbanfudasyo','延å½å¯º', 'ããããã', 'enmeiji', 38) ,(55,'第55çªææ','ã ãããã ããã°ããµã ãã', 'daigojyugobanfudasyo','åå å', 'ãªãããã¼ã', 'nankoubou', 38) ,(56,'第56çªææ','ã ãããã ãããã°ããµã ãã', 'daigojyurokubanfudasyo','泰山寺', 'ããããã', 'taisanji', 38) ,(57,'第57çªææ','ã ãããã ããªãªã°ããµã ãã', 'daigojyunanabanfudasyo','æ ç¦å¯º', 'ãããµãã', 'eifukuji', 38) ,(58,'第58çªææ','ã ãããã ãã¯ã¡ã°ããµã ãã', 'daigojyuhachiichibanfudasyo','ä»é寺', 'ããããã', 'senyuuji', 38) ,(59,'第59çªææ','ã ãããã ããã ãã°ããµã ãã', 'daigojyukyubanfudasyo','å½å寺', 'ããã¶ãã', 'kokubunji', 38) ,(60,'第60çªææ','ã ããããã ãã°ããµã ãã', 'dairokujyubanfudasyo','横峰寺', 'ããã¿ãã', 'yokomineji', 38) ,(61,'第61çªææ','ã ããããã ããã¡ã°ããµã ãã', 'dairokujyuichibanfudasyo','é¦å寺', 'ããããã', 'kouonji', 38) ,(62,'第62çªææ','ã ããããã ãã«ã°ããµã ãã', 'dairokujyunibanfudasyo','å®å¯¿å¯º', 'ã»ããã ã', 'houjyuji', 38) ,(63,'第63çªææ','ã ããããã ãããã°ããµã ãã', 'dairokujyusanbanfudasyo','å祥寺', 'ãã£ãããã', 'kissyouji', 38) ,(64,'第64çªææ','ã ããããã ãããã°ããµã ãã', 'dairokujyuyonbanfudasyo','åç¥å¯º', 'ã¾ããã¿ã', 'maegamiji', 38) ,(65,'第65çªææ','ã ããããã ããã°ããµã ãã', 'dairokujyugobanfudasyo','ä¸è§å¯º', 'ããããã', 'sankakuji', 38) ,(66,'第66çªææ','ã ããããã ãããã°ããµã ãã', 'dairokujyurokubanfudasyo','é²è¾ºå¯º', 'ããã¹ãã', 'unbenji', 37) ,(67,'第67çªææ','ã ããããã ããªãªã°ããµã ãã', 'dairokujyunanabanfudasyo','大è寺', 'ã ãããã', 'daikouji', 37) ,(68,'第68çªææ','ã ããããã ãã¯ã¡ã°ããµã ãã', 'dairokujyuhachibanfudasyo','ç¥æµé¢', 'ããããã', 'jinnein', 37) ,(69,'第69çªææ','ã ããããã ããã ãã°ããµã ãã', 'dairokujyukyubanfudasyo','観é³å¯º', 'ããããã', 'kanonji', 37) ,(70,'第70çªææ','ã ããªãªãã ãã°ããµã ãã', 'dainanajyubanfudasyo','æ¬å±±å¯º', 'ãã¨ãã¾ã', 'motoyamaji', 37) ,(71,'第71çªææ','ã ããªãªãã ããã¡ã°ããµã ãã', 'dainanajyuichibanfudasyo','弥谷寺', 'ããã ã«ã', 'iyadaniji', 37) ,(72,'第72çªææ','ã ããªãªãã ãã«ã°ããµã ãã', 'dainanajyunibanfudasyo','æ¼è¶ç¾ 寺', 'ã¾ãã ãã', 'mandaraji', 37) ,(73,'第73çªææ','ã ããªãªãã ãããã°ããµã ãã', 'dainanajyusanbanfudasyo','åºé迦寺', 'ãã ã£ãããã', 'syussyakaji', 37) ,(74,'第74çªææ','ã ããªãªãã ãããã°ããµã ãã', 'dainanajyuyonbanfudasyo','ç²å±±å¯º', 'ãããã¾ã', 'kouyamaji', 37) ,(75,'第75çªææ','ã ããªãªãã ããã°ããµã ãã', 'dainanajyugobanfudasyo','åé寺', 'ããã¤ãã', 'zentsuuji', 37) ,(76,'第76çªææ','ã ããªãªãã ãããã°ããµã ãã', 'dainanajyurokubanfudasyo','éå寺', 'ããããã', 'kouzouji', 37) ,(77,'第77çªææ','ã ããªãªãã ããªãªã°ããµã ãã', 'dainanajyunanabanfudasyo','éé寺', 'ã©ããã ãã', 'douryuuji', 37) ,(78,'第78çªææ','ã ããªãªãã ãã¯ã¡ã°ããµã ãã', 'dainanajyuhachibanfudasyo','é·ç §å¯º', 'ãããããã', 'gousyouji', 37) ,(79,'第79çªææ','ã ããªãªãã ããã ãã°ããµã ãã', 'dainanajyukyubanfudasyo','é«ç §é¢', 'ããããããã', 'kousyouin', 37) ,(80,'第80çªææ','ã ãã¯ã¡ãã ãã°ããµã ãã', 'daihachijyubanfudasyo','å½å寺', 'ããã¶ãã', 'kokubunji', 37) ,(81,'第81çªææ','ã ãã¯ã¡ãã ããã¡ã°ããµã ãã', 'daihachijyuichibanfudasyo','ç½å³¯å¯º', 'ããã¿ãã', 'shiromineji', 37) ,(82,'第82çªææ','ã ãã¯ã¡ãã ãã«ã°ããµã ãã', 'daihachijyunibanfudasyo','æ ¹é¦å¯º', 'ãããã', 'negoroji', 37) ,(83,'第83çªææ','ã ãã¯ã¡ãã ãããã°ããµã ãã', 'daihachijyusanbanfudasyo','ä¸å®®å¯º', 'ãã¡ã®ã¿ãã', 'ichinomiya', 37) ,(84,'第84çªææ','ã ãã¯ã¡ãã ãããã°ããµã ãã', 'daihachijyuyonbanfudasyo','å±å³¶å¯º', 'ããã¾ã', 'yashimaji', 37) ,(85,'第85çªææ','ã ãã¯ã¡ãã ããã°ããµã ãã', 'daihachijyugobanfudasyo','å «æ 寺', 'ãããã', 'yakuriji', 37) ,(86,'第86çªææ','ã ãã¯ã¡ãã ãããã°ããµã ãã', 'daihachijyurokubanfudasyo','å¿åº¦å¯º', 'ãã©ã', 'shidoji', 37) ,(87,'第87çªææ','ã ãã¯ã¡ãã ããªãªã°ããµã ãã', 'daihachijyunanabanfudasyo','é·å°¾å¯º', 'ãªããã', 'nagaoji', 37) ,(88,'第88çªææ','ã ãã¯ã¡ãã ãã¯ã¡ã°ããµã ãã', 'daihachijyuhachibanfudasyo','大窪寺', 'ãããã¼ã', 'ookuboji', 37);
Spring Bootã§è©¦ãã¦ã¾ãã
â /jpa-example/build.gradle
plugins { id 'org.springframework.boot' version '2.7.4' id 'io.spring.dependency-management' version '1.0.14.RELEASE' id 'java' } group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = '1.8' configurations { compileOnly { extendsFrom annotationProcessor } } repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'org.postgresql:postgresql' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' } tasks.named('test') { useJUnitPlatform() }
â /jpa-example/src/main/resources/application.properties
spring.datasource.driver-class-name=org.postgresql.Driver spring.datasource.url=jdbc:postgresql://localhost:5434/test spring.datasource.username=postgres spring.datasource.password=postgres
â /jpa-example/src/main/java/com/example/demo/entity/ShikokuOhenro.java
package com.example.demo.entity; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import lombok.Builder; import lombok.Data; @Entity @Table(name="shikoku_ohenro") @Data @Builder public class ShikokuOhenro { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Long id; @Column(name="name_fudasyo") private String nameFudasyo; @Column(name="kana_name_fudasyo") private String kanaNameFudasyo; @Column(name="rome_name_fudasyo") private String romeNameFudasyo; @Column(name="name_temple") private String nameTemple; @Column(name="kana_name_temple") private String kanaNameTemple; @Column(name="rome_name_temple") private String romeNameTemple; @Column(name="prefectures_id") private Long prefecturesId; }
â /jpa-example/src/main/java/com/example/demo/entity/Prefectures.java
package com.example.demo.entity; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import lombok.Builder; import lombok.Data; @Entity @Table(name="prefectures") @Data @Builder public class Prefectures { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Long id; @Column(name="name_prefecture") private String namePrefecture; @Column(name="kana_name_prefecture") private String kanaNamePrefecture; @Column(name="rome_name_prefecture") private String romeNamePrefecture; @Column(name="name_prefectural_capital") private String namePrefecturalCapital; @Column(name="kana_name_prefectural_capital") private String kanaNamePrefecturalCapital; @Column(name="rome_name_prefectural_capital") private String romeNamePrefecturalCapital; @Column(name="area_id") private Long areaId; }
â /jpa-example/src/main/java/com/example/demo/entity/custom/ShikokuOhenroInfo.java
package com.example.demo.entity.custom; import lombok.Builder; import lombok.Data; @Data @Builder public class ShikokuOhenroInfo { private String nameFudasyo; private String kanaNameFudasyo; private String romeNameFudasyo; private String nameTemplate; private String kanaNameTemplate; private String romeNameTemplate; private String namePrefecture; private String kanaNamePrefecture; private String romeNamePrefecture; private String namePrefecturalCapital; private String kanaNamePrefecturalCapital; private String romeNamePrefecturalCapital; }
â /jpa-example/src/main/java/com/example/demo/repository/ShikokuOhenroRepository.java
package com.example.demo.repository; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import com.example.demo.entity.ShikokuOhenro; public interface ShikokuOhenroRepository extends JpaRepository<ShikokuOhenro, Long> { @Query(value="SELECT " + "so.name_fudasyo " + ", so.kana_name_fudasyo " + ", so.rome_name_fudasyo " + ", so.name_temple " + ", so.kana_name_temple " + ", so.rome_name_temple " + ", p.name_prefecture " + ", p.kana_name_prefecture " + ", p.rome_name_prefecture " + ", p.name_prefectural_capital " + ", p.kana_name_prefectural_capital " + ", p.rome_name_prefectural_capital " + "FROM shikoku_ohenro so " + "LEFT JOIN prefectures p ON so.prefectures_id = p.id " , nativeQuery=true) List<Object[]> findOhenroInfo(); }
â /jpa-example/src/main/java/com/example/demo/service/ShikokuOhenroServiceImpl.java
package com.example.demo.service; import java.util.ArrayList; import java.util.List; import java.util.Objects; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.example.demo.entity.custom.ShikokuOhenroInfo; import com.example.demo.repository.ShikokuOhenroRepository; @Service public class ShikokuOhenroServiceImpl { @Autowired private ShikokuOhenroRepository shikokuOhenroRepository; public List<ShikokuOhenroInfo> findShikokuOhenroInfo () { List<Object[]> shikokuOhenroInfoObjList = shikokuOhenroRepository.findOhenroInfo(); List<ShikokuOhenroInfo> shikokuOhenroInfoList = new ArrayList<>(); for (Object[] objArr: shikokuOhenroInfoObjList) { shikokuOhenroInfoList.add(ShikokuOhenroInfo.builder() .nameFudasyo(Objects.nonNull(objArr[0])? objArr[0].toString(): null) .kanaNameFudasyo(Objects.nonNull(objArr[1])? objArr[1].toString(): null) .romeNameFudasyo(Objects.nonNull(objArr[2])? objArr[2].toString(): null) .nameTemplate(Objects.nonNull(objArr[3])? objArr[3].toString(): null) .kanaNameTemplate(Objects.nonNull(objArr[4])? objArr[4].toString(): null) .romeNameTemplate(Objects.nonNull(objArr[5])? objArr[5].toString(): null) .namePrefecture(Objects.nonNull(objArr[6])? objArr[6].toString(): null) .kanaNamePrefecture(Objects.nonNull(objArr[7])? objArr[7].toString(): null) .romeNamePrefecture(Objects.nonNull(objArr[8])? objArr[8].toString(): null) .namePrefecturalCapital(Objects.nonNull(objArr[9])? objArr[9].toString(): null) .kanaNamePrefecturalCapital(Objects.nonNull(objArr[10])? objArr[10].toString(): null) .romeNamePrefecturalCapital(Objects.nonNull(objArr[11])? objArr[11].toString(): null) .build()); } return shikokuOhenroInfoList; } }
â /jpa-example/src/main/java/com/example/demo/controller/ShikokuOhenroController.java
package com.example.demo.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import com.example.demo.entity.custom.ShikokuOhenroInfo; import com.example.demo.service.ShikokuOhenroServiceImpl; @RestController public class ShikokuOhenroController { @Autowired private ShikokuOhenroServiceImpl shikokuOhenroServiceImpl; @GetMapping(value="shikoku-ohenro-info") public List<ShikokuOhenroInfo> findShikokuOhenroInfo() { return shikokuOhenroServiceImpl.findShikokuOhenroInfo(); } }
⧠ã§ãå®è¡ãã¦ããã©ã¦ã¶ã§ã¢ã¯ã»ã¹ããã¨ã
⧠åå¾ã¯ã§ãã¦ã模æ§ã
ãï½ããJPAï¼Java Persistence APIï¼ã§nativeQueryãå®æ½ããå ´åãã©ãããã®ããã¹ããã©ã¯ãã£ã¹ãªãã ããã...
æ¯åº¦ã¢ã¤ã¢ã¤æãå端ãªã...
ä»åã¯ãã®ã¸ãã§ã
Â
Â